Skip to content

Instantly share code, notes, and snippets.

@WickyNilliams
Last active January 30, 2020 17:46
Show Gist options
  • Save WickyNilliams/d0fd94d84ac27feb93fe to your computer and use it in GitHub Desktop.
Save WickyNilliams/d0fd94d84ac27feb93fe to your computer and use it in GitHub Desktop.
fast builds with grunt and browserify
module.exports = function(grunt) {
"use strict";
grunt.initConfig({
pkg : grunt.file.readJSON("package.json"),
paths : {
src : "<%= pkg.main %>",
dest : "dist/out.js"
},
// using watch is slow because it runs browserify from cold start
watch: {
options : {
atBegin : true
},
browserify : {
files : ["src/**/*.js"],
tasks : ["browserify:dev"] // no incremental builds :(
}
},
browserify : {
dev : {
src : ["<%= paths.src %>"],
dest : "<%= paths.dest %>",
options : {
browserifyOptions : {
debug : true
}
}
}
}
});
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-browserify");
grunt.registerTask("default", ["watch"]);
};
module.exports = function(grunt) {
"use strict";
grunt.initConfig({
pkg : grunt.file.readJSON("package.json"),
paths : {
src : "<%= pkg.main %>",
dest : "dist/out.js"
},
browserify : {
dev : {
src : ["<%= paths.src %>"],
dest : "<%= paths.dest %>",
options : {
watch : true, // use watchify for incremental builds!
keepAlive : true, // watchify will exit unless task is kept alive
browserifyOptions : {
debug : true // source mapping
}
}
},
dist : {
src : ["<%= paths.src %>"],
dest : "<%= paths.dest %>"
}
}
});
grunt.loadNpmTasks("grunt-browserify");
grunt.registerTask("dev", ["browserify:dev"]);
grunt.registerTask("dist", ["browserify:dist"]);
grunt.registerTask("default", ["dev"]);
};
@WickyNilliams
Copy link
Author

@padsbanger @DeeperX I've not tested this but i think it goes something like this...

If you use LESS (or anything else) and have a grunt watching for changes, you can drop the keepAlive:true option from browserify task. Instead put it before watch in your grunt task e.g.

grunt.registerTask("default", ["browserify:dev", "watch"]);

watch stops grunt exiting so it should work OK

@wggley
Copy link

wggley commented Jan 30, 2020

Thanks @WickyNilliams, you're still helping ppl on 2020!

@WickyNilliams
Copy link
Author

@wggley haha crazy. Glad to be of help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment