jackfranklin / gulp-load-plugins

Automatically load in gulp plugins
https://github.com/jackfranklin/gulp-load-plugins
MIT License
757 stars 55 forks source link

Option to add in base path to require call #31

Closed u01jmg3 closed 10 years ago

u01jmg3 commented 10 years ago

When using gulp I instead choose to install all my components globally. This means in order to load my gulp plugins I must specify a base path along with the name of the gulp plugin.

e.g.

var base = 'C:/Users/username/AppData/Roaming/npm/node_modules/';
var uglifyjs = require(base + 'gulp-uglify');

Could gulp-load-plugins be extended to allow this path to be passed in? No worries if it's not what you want your plugin to do.

jackfranklin commented 10 years ago

To me, it seems very odd that you do things that way - and certainly something that isn't common at all - to that end it's also not something that I will be adding to the plugin, I'm afraid.

u01jmg3 commented 10 years ago

For each project I use gulp for, I am re-using the exact same plugins along with a template gulpfile.js. It therefore made sense to install the plugins globally to save re-loading them each time for each new project. It also makes updating simpler as you do it only once.

I'd be glad to hear your comments if my logic is flawed...

adam-lynch commented 10 years ago

@u01jmg3 sounds like you just need to add ;C:/Users/username/AppData/Roaming/npm/node_modules to the end of your PATH environment variable. Then you can just var uglifyjs = require('gulp-uglify'); and it'll work.

u01jmg3 commented 10 years ago

Thanks @adam-lynch

I've already tried that and gulp just complains it cannot find the module

jackfranklin commented 10 years ago

@u01jmg3 I would really recommend not using this approach - the entire idea of modules and dependencies is they are done on a per project basis - even if you happen to have some projects that share the same set. Why not create your template gulpfile and a package.json with all the dependencies, and then all you need to do is run a quick npm install and you have everything local to the project and all ready to go?

@adam-lynch I don't think that would work, as require only looks locally, and doesn't take $PATH into it, as far as I'm aware.

u01jmg3 commented 10 years ago

Thanks @jackfranklin - appreciate your reply

I know I am breaking the normal way of doings things but we're not talking about some projects that share the same set; we're talking about all my projects using the exact same gulp plugins each time to do the same tasks of minifying, obfuscating, etc.

Also the quick run you mention isn't quick for me. At the moment I'm using 21 gulp plugins which take around 5-7 minutes to install. One might argue that 21 is on the high side and it probably is. I believe installing locally is an unnecessary duplication of data which can be removed by going global and installing just the once. What benefits do I get from going local other than it being the normal way?

Alternatively, with bower dependencies I agree local is the only approach because projects will use different libraries and unlike gulp, bower dependencies are installed and used in your web app.

jackfranklin commented 10 years ago

But you only have to do the npm install once though, right, when you first create the new project? The fact that require doesn't look globally should be your biggest clue that local installs are the way to go.

Anyway, I can see we have totally different opinions here, so there's not too much point continuing - but I'm afraid I can't see this option being supported anytime soon.

Jack.

adam-lynch commented 10 years ago

@jackfranklin I'm probably only thinking of CLI stuff like gulp (not using require)

u01jmg3 commented 10 years ago

@jackfranklin yes once per project. If you install globally though it's once, period, no matter how many projects you create. I know require doesn't currently look globally but libraries evolve over time and if nobody ever questioned how we work we'd never move onto different ways of doing things.

Agreed - no worries