A tool for automatically discovering and "sourcing" your dependency packages from Bower and NPM and any other packagers.
npm install --save-dev source-deps
var deps = require('source-deps'),
concat = require('gulp-concat');
gulp.task('bundle', function () {
var depFiles = deps({
packagers: ['bower', 'npm'],
includeDevPackages: false,
logOutput: false,
overrides: {
angular: 'lib/angular.min.js'
},
ignore: ['normalize.css'],
order: [
'angular',
'angular-mocks'
],
include: [
'some-package-apparently-not-listed-as-dependency'
],
recursive: true // Pull in dependencies of dependencies (in proper order too :)
});
gulp.src(depFiles)
.pipe(concat(['src/**/*.js']))
.pipe(gulp.dest('all.js'));
});
This example pulls in all production dependencies from package.json
and bower.json
.
Overrides tells it where to find dist files for a library where the automatic guessing is not working.
It is very important that you make sure each dependency package has correct paths to the dist files.
deps({
packagers: ['bower', 'npm'],
logOutput: true
})
This will show you how many files get pulled in as well as which packages are likely not being pulled properly.
As of 0.2.5
you can control the ordering of your dependant files now! Very helpful, like so.
var deps = require('source-deps'),
depFiles = deps({
packagers: ['bower'],
order: [
'angular',
'angular-mocks',
'angular-animate'
]
});
This will happily prevent your dependencies from being loaded out of proper resolution order :)
And now you can ignore certain packages by just adding them to the ignore
option like so:
var deps = require('source-deps'),
depFiles = deps({
packagers: ['bower'],
order: [
'angular',
'angular-mocks'
],
ignore: [
'angular-animate'
]
});
This is for a number of odd situations where there is a package present that is either:
A) Not listed as a dependency
B) Ignored already
C) Ignored by a future feature that allows for exclusion patterns
... and needs to be included anyway. In other words it overrides any exclusions.
depFiles = deps({
packagers: ['bower'],
ignore: ['said-package'],
include: ['said-package'] // Takes priority
});
Oh yeah... this does exactly what you think it does. Bye, bye RequireJS shims on the frontend.
depFiles = deps({
packagers: ['bower'],
recursive: true
});
- Pulls in all dependencies-of-dependencies
- Ignores duplicate occurences of dependencies (i.e. won't pull in JQuery 900 times ;)
- Respects
order
,ignore
, andinclude
. - By default will load dependencies BEFORE the package that pulled them in, usually resulting in resolution order being met correctly.
- Use
order
to resolve anything that pulls in too early / too late as a result of overlapping secondaries amongst packages.