It's easy! There are only 2 steps:
-
Install required packages with NPM:
npm install browserify babelify
-
Create package.json with the following content (here main.js file is source file and bundle.js is output file. Also note we are applying transformer to browserify command):
{ "scripts": { "build-js": "browserify -t babelify main.js > bundle.js" } }
Thats it! Now whenever you feel to build up your ES6 code (main.js), just fire npm run build-js
. If you are wondering why building via NPM: it allows you to call commands that are installed on project level (so you don't have to pollute global node_modules).
So have a fun writing JavaScript of tomorrow! :)