Will
Will

Reputation: 924

Is it possible to setup Gulp in a distributed fashion?

Here's what I want to do:

We currently have something similar setup with Grunt (although without the Gruntfile.js copy stuff). It works pretty well to have a common setup for each of our apps, but also several custom Bower components. Just have to bring it in as a dependency and it magically works.

The main issue I've run into so far is when I add my-gulp to myApp's dependencies, run the install, my-gulp comes in just fine, however the individual plugins (my-gulp dependencies) aren't seen. They're installed, but running something like gulp default or whatever shows them missing.

I've tried to setup Gulp dependencies (in my-gulp) under "dependencies" as opposed to "devDependencies", yet still not quite working.


Does anyone have any experience doing something like this? Am I doing something blatantly stupid here?

Any help is awesome!

Thanks, everyone :)

Upvotes: 0

Views: 116

Answers (1)

Justin Howard
Justin Howard

Reputation: 5643

The problem is the way npm handles nested dependencies. When you install your "my-gulp" package, the directory tree looks like this:

| myApp
|-- node_modules
    |-- my-gulp
       |-- node_modules
           |-- gulp_dependency

As you can see, the dependencies of "my-gulp" are buried inside its own node_modules directory. myApp cannot access them.

You could use something like npm-flatten to move those to the top directory. Otherwise you'll be forced to add each dependency to myApp's package.json.

Edit: As indicated in your gist, you can load the dependencies by path instead of package name. Instead of copying your gulpfile, simply require it from myApp, then load its dependencies with a relative path:

// myApp/gulpfile.js
require('my-gulp/gulpfile.js');

// my-gulp/gulpfile.js
var gulpDep = require('./node_modules/gulp-dependency');

Note: This won't work if you use npm dedupe.

Upvotes: 1

Related Questions