Metalsmith plugin to bundle JS with browserify
JavaScript HTML
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
fixtures
.gitignore
.travis.yml
README.md
index.js
index.test.js
package.json

README.md

Build Status

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']
);

// do stuff with the bundle
b.bundle.external(/*...*/);

metalsmith(__dirname)
  .use(b) // use the plugin
  .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
  }
}