I set up a view task with grunt-contrib-watch , which starts building the browser using grunt-browserify when the source files change.
To put it into action, here is an example of Gruntfile.js:
module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), watch: { files: ['app/app.js'], tasks: ['browserify'] }, browserify: { dist: { files: { 'app/app.bundle.js': ['app/app.js'], } } } }); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-browserify'); };
Now you can simply use it to view the changes by calling:
grunt watch
Note that you need to have a grunt along with grunt-contrib-watch and grunt-browserify .
Alternatively, you can use Gulp instead of Grunt. A similar result can be achieved with gulp-browserify along with gulp-watch with a less detailed build file and some potential winnings.
source share