-
Notifications
You must be signed in to change notification settings - Fork 5
Grunt: Recipe Browserify (and ES6)
Marco Solazzi edited this page Oct 5, 2015
·
2 revisions
This recipe will guide you to setup browserify in Wok workflow.
Since browserify generates inline sourcemaps, we'll use exorcise to move them to external files.
Finally, you may include ES6 support by using babel and babelify
Note: right now watch mode might not work. See this issue for details
##Installation and Requirements
Install grunt-browserify and grunt-exorcise plugin:
npm install grunt-browserify grunt-exorcise --save-dev##Task Configuration
- Create a
browserify.jsfile inbuild/grunt-tasksand paste the following boilerplate code:
/*jshint node:true */
module.exports = {
dev: {
options: {
alias: [],
browserifyOptions: {
//build sourcemaps
debug: true
},
//delegate to watchify
watch: true
},
files: [
{
expand: true,
cwd: '<%= paths.src.assets %>/',
src: '<%= paths.js %>/*.js',
dest: '<%= paths.dist.assets %>'
}
]
},
dist: {
options: {
browserifyOptions: {
debug: false
}
},
files: '<%= browserify.dev.files %>'
}
};- Create a
exorcise.jsfile inbuild/grunt-tasksand paste the following boilerplate code:
/*jshint node:true */
module.exports = {
dev: {
options: {},
files: [
{
expand: true,
cwd: '<%= paths.dist.assets %>/',
src: '<%= paths.js %>/*.js',
dest: '<%= paths.dist.assets %>',
ext: '.js.map'
}
]
}
};-
Comment or delete
jssub-task inbuild/grunt-tasks/copy.jsand build/grunt-tasks/watch.js -
Edit
build/grunt-tasks/aliases.yml. Add the development tasks to thedevlist just after thecopytask
dev:
...
- browserify:dev
- exorciseThen add the production sub-task to the dist list just after the copy task
dist:
...
- browserify:dist- Enjoy
Optional: add ES6 Support (babel)
- install babelify
npm install babelify --save-dev- add a global task's
optionswith the following properties inbuild/grunt-tasks/browserify.js
/*jshint node:true */
module.exports = {
options: {
require: ['babelify/polyfill'],
transform: [
['babelify', {
optional: ['strict'],
loose: [
'es6.arrowFunctions',
'es6.blockScoping',
'es6.classes',
'es6.constants',
'es6.forOf',
'es6.modules',
'es6.parameters',
'es6.properties.computed',
'es6.properties.shorthand',
'es6.tailCall',
'es6.templateLiterals',
'es6.regex.unicode',
'es6.regex.sticky'
]
}]
],
},
dev: {
//...
},
dist: {
//...
},
};