Last active
January 30, 2020 17:46
-
-
Save WickyNilliams/d0fd94d84ac27feb93fe to your computer and use it in GitHub Desktop.
fast builds with grunt and browserify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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 beforewatch
in your grunt task e.g.watch
stops grunt exiting so it should work OK