An easy way to deal with libraries.
After installing libraries via bower you can use this gulp plugin to get streams to all your libraries sources you need to copy to your project. You don't need to specify for each project again, where exactly the JavaScript or CSS is located, that you need to copy over.
A lengthy explanation of the motivation behind this library can be found in a blog post (TODO: write blog post) I wrote.
This plugin examines all your dependencies, if they have specified metadata in their package (see Metadata for your library). If they don't have metadata, it will look up the metadata for this library in a central repository (so this pugin also works for libraries, that don't want to specify metadata on their own). After that you can get access to all JavaScript, CSS or whatever resources the libraries exported via this plugin.
To use this plugin, you need to require
it in your Gulpfile and initialize it:
var libraries = require('gulp-libraries')();
You can pass several options to the initialization of the plugin, to configure it. The plugin has sensible default values for all the options. The options are described further down.
After you have initialized the plugin, you can get access to the files of your libraries
by calling the modules files
method. To just copy all the JavaScript files from all your
libraries to build/libs
you can write the following task:
gulp.task('libsjs', function() {
libraries.files('js')
.pipe(gulp.dest('build/libs'));
});
A library can export any kind of resources. The most common ones are js
(JavaScript files),
css
(CSS files). (TODO: Define a list somewhere).
TODO: Ordering of packages
TODO: How the metadata file has to look
TODO
gulp-libraries(options)
You need to call this in your buildscript to initialize the library.
object
or undefined
)An optional object to configure the library. The following options are available:
config
(default: libraries.json
) - The relative (from the root of your project) path tometadataRegistry
(default: https://github.com/timroes/gulp-libraries-registry/
) - The base urlfile:/tmp/jquery/2.0.0/metadata.json
) if you set thisfile:/tmp/
. If you set this option, because you are missing metadata in the officialignoreCyclicDependencies
TODOgulp-libraries.files(types, opts, gulpOpts)
Return a file stream (that you can call .pipe
on) for the specified file types.
string
or string[]
)Either a string or an array of strings. Define the type of files which to create a stream
for (e.g. js
or css
). (TODO: Link to list) If you specify an array of types, the order
in which the resources appear in the array will determine the order of the files in the stream.
object
or undefined
)An optional parameter, that can hold options on how to create the stream. There following keys can be set in the object:
keepHierarchy
(default: false
) - By default this plugin will flatten all packages, so they will all be put in thegulp.dest
. If you set keepHierarchy
to true
the originalgulp.dest('tmp')
you will end up having the folder structure tmp/jquery/dist/jquery.min.js
tmp/jquery.min.js
.object
or undefined
)An optional parameter that will be passed to the gulp.src
function as a second parameter.
You can set there any options gulp.src
understands.