JSPM

  • Created
  • Published
  • Downloads 54571
  • Score
    100M100P100Q145708F

Grunt task for node-browserify

Package Exports

  • grunt-browserify/tasks/browserify

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (grunt-browserify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

build status

grunt-browserify

Grunt task for node-browserify

Getting Started

Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-browserify

Then add this line to your project's grunt.js gruntfile:

grunt.loadNpmTasks('grunt-browserify');

Documentation

Settings

  • ignore - array, optional - files to ignore
  • requires - array, optional - modules to require
  • aliases - array, optional - aliases in form to:from1:from2, see bundle.alias
  • src - array - files or file patterns to browserify. Alias entries
  • prepend - array, optional - files or file patterns to prepend
  • append - array, optional - files or file patterns to append
  • hook - function, optional - receives bundle as argument, could to be used further modify bundle.

For simplest usecase, add this to grunt.initConfig()

    browserify: {
    'dist/bundle.js': "src/**/*.js"
    }

Example with all settings:

    pkg: '<json:package.json>',
    meta: {
      banner: '\n/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
        '<%= grunt.template.today("yyyy-mm-dd") %>\n ' + '<%= pkg.homepage ? "* " + pkg.homepage + "\n *\n " : "" %>' +
        '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;\n' +
        ' * Licensed under the <%= _.pluck(pkg.licenses, "type").join(", ") %> license */'
    },
    browserify: {
      'full-example': {
        requires: ['traverse'],
        aliases: ['jquery:jquery-browserify'],
        src: ['src/**/*.js'],
        dest: 'dist/bundle.<%= pkg.version %>.js'
        prepend: ['<banner:meta.banner>'],
        append: [],
        beforeHook: function(bundle) {
          // Do something with bundle before anything else
        },
        hook: function (bundle) {
          // Do something with bundle
        }
      }
    }

Using Browserify Plugins

You can use Browserify plugins by using the beforeHook option. This hook is called before anything else and is passed the newly created bundle. You can use this hook at enable plugins:

     browserify: {
      "dist/bundle.js": {
        entries: ['src/**/*.js'],
        beforeHook: function(bundle) {
          var stringify = require('stringify');
          bundle.use(stringify(['.hjs', '.html', '.whatever']));
        }
      }
    }

Using Browserify Plugins

You can use Browserify plugins by using the beforeHook option. This hook is called before anything else and is passed the newly created bundle. You can use this hook at enable plugins:

browserify: {
  "dist/bundle.js": {
    entries: ['src/**/*.js'],
    beforeHook: function(bundle) {
      var stringify = require('stringify');
      bundle.use(stringify(['.hjs', '.html', '.whatever']));
    }
  }
}

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Release History

v0.1.0

  • Initial release

v0.1.1

  • Properly support compact and full grunt task syntax

License

Copyright (c) 2012 Camille Moncelier Licensed under the MIT license.