README
Shampoo JS
Sorry, this documentation is a little out of date.
I am working on a full website with documentation which is why the README is a little old. Wasn't expecting people to find this library so soon...
The new version works:
- From the command line
- With a very simple Shampoofile.js or Shampoofile.coffee
- Continues to work as a Grunt task
The ultimate Grunt Browserify task.
- Run once or watch files for changes
- Uses a cache for super speed (instant builds)
- CoffeeScript support built in
- Alias mappings
- Shim non CommonJS files
- Super simple configuration and good defaults
- More...
Quick Start
If you already know Grunt, for basic usage create a Gruntfile.js
as below filling in your destination path and source path.
// Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
shampoo: {
files: {
'./build/dest/path.js': './source/path.js'
},
},
});
grunt.loadNpmTasks('grunt-browserifying');
}
Then from your console:
grunt browserifying
This will start the task and watch the source file and all of its require'd dependencies for changes. It will rebuild when a file change is detected. It uses caching so its very fast. To quit watching, use CTRL-C
.
Getting Started
This plugin requires Grunt ~0.4.2
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-browserifying --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-browserifying');
The Browserifying Grunt Plugin
Overview
In your project's Gruntfile, add a section named browserifying
to the data object passed into grunt.initConfig()
.
Include a files
Object where:
- The keys are the destination file for the Browserify build (remember to include the ".js")
- The value is either a
String
orArray
ofString
that represents the source files. The source files may be either.js
or.coffee
files. Remember to:- Include the extension (.js or .coffee).
- Include the "./" part of the path
The source files are relative to the directory from where grunt
is being run.
Optionally include an options
Object. See the Options section for more info.
grunt.initConfig({
browserifying: {
options: {
// See the options sections for all options.
// popular option watches for file changes and updates only the changed
// files. If watch is missing or set to false, browserifying will only
// bundle the files once and exit.
watch: true
},
files: {
'./build/path/example.js': './source/path.js'
},
},
});
Running the Grunt Task
Run the grunt task from the command line using:
grunt browserify_plus
CoffeeScript
It works with CoffeeScript files (no configuration required):
grunt.initConfig({
browserifying: {
options: {},
files: {
'./build/path/example.js': './source/path.coffee'
// .coffee files work
},
},
});
Multiple Source Files
For multiple files, pass in an array (feel free to mix js and coffee files):
grunt.initConfig({
browserifying: {
options: {},
files: {
'./build/path/example.js': ['./source/path.coffee', './source/path_2.js']
// Array of String for sources works
},
},
});
Multiple Browserify Bundles
You can have multiple builds going on simultaneously:
grunt.initConfig({
browserifying: {
options: {
},
files: {
// Multiple key/value pairs works to create multiple Browserify bundles
'./build/path/example.js': ['./source/path.coffee', './source/path_2.js']
'./build/path/example-2.js': './source/example-2.js'
},
},
});
Options
All options:
grunt.initConfig({
browserifying: {
options: {
watch: false, // watch files for changes with caching (default true)
map: {
'underscore': './lib/underscore.js',
'jquery': {
exports: '