grunt-watchify
Grunt task for node-browserify.
Getting Started
This plugin requires Grunt ~0.4.0
and Node >=0.8.x
.
Install this grunt plugin with:
npm install grunt-watchify --save-dev
Then add this line to your project's Gruntfile.js
Gruntfile:
grunt;
Common errors
Running "watchify:source" taskFatal error: module "src/main.js" not found in
Is the src
attribute starting with ./
?
grunt-watchify
is different from grunt-browserify
. It follows the
nodejs require.resolve() algorithm.
... src: './src/main.js' ......
Differences with grunt-browserify
grunt-watchify
watches the dependencies like watchify and rebuilds the bundle, when one dependency is modified.grunt-watchify
caches the dependencies making the rebuild process very fast (useful for big projects).- The configuration is different. You have the
options
of browserify pluskeepalive
andcallback
. - The instance of browserify is passed to
callback
where you can use the api of browserify. Remember to return the instance. - The
keepalive
is useful if you usegrunt-watchify
alone. It works like in grunt-contrib-connect#keepalive.
grunt;
- The
src
makes difference betweenprocess
and./process
:
grunt;
Your project files usually start with ./
.
- You can use the glob only with your project files and not for the modules in
node_modules
.
Examples
You find this example in the directory example
.
grunt-watchify
builds thebundle.js
and watches the dependencies.grunt-contrib-watch
watches thebundle.js
and triggerslivereload
when it changes.grunt-contrib-connect
serves the files.grunt-contrib-livereload
is used only for the livereload snippet.
/* * grunt-watchify * http://github.com/amiorin/grunt-watchify * * Copyright (c) 2013 Alberto Miorin, contributors * Licensed under the MIT license. */ 'use strict'; var path = ; var lrSnippet = livereloadSnippet;var { return connect;}; module { grunt; grunt; grunt; grunt; grunt; grunt;};
How can you start grunt
:
# with other tasks like connect and watch # done() is called grunt # alone like watchify # done() is *never* called grunt watchify:example:keepalive
Credits
- browserify ;-)
- watchify for the cache code
- grunt-browserify for the tests