Metalsmith - Browserify
Metalsmith plugin to bundle JS with browserify
Installation
npm install metalsmith-browserify --save
metalsmith-browserify does not bundle browserify. You need to install it yourself in your package.
This is to avoid usage of an outdated browserify version with metalsmith-browserify.
Usage
var metalsmith = require('metalsmith');
var browserify = require('metalsmith-browserify');
metalsmith(__dirname)
.use(browserify({
dest: 'js/bundle.js',
entries: ['./src/js/index.js'],
sourcemaps: false,
watch: false
}))
.build(function (err, files) {
if (err) {
throw err;
}
});
See browserify api for available options.
If you need to manipulate the created browserify bundle do:
var metalsmith = require('metalsmith');
var browserify = require('metalsmith-browserify');
var b = browserify({
dest: 'js/bundle.js',
entires: ['./src/js/index.js']
);
b.bundle.external();
metalsmith(__dirname)
.use(b)
.build()
It can also be used with metalsmith.json
by adding the plugin like this:
{
"plugins": {
"metalsmith-browserify": {
"dest": "javascripts/bundle.js",
"entries": ["src/javascripts/index.js"],
"sourcemaps": false,
"watch": false
}
}
}
Or assume the defaults (dest: bundle.js
, args: []):
{
"plugins": {
"metalsmith-browserify": true
}
}