Browser support for ES6 is growing, but to be sure your code will work on environments that dont fully support it, you can use Babel, the ES6/7 to ES5 transpiler, try it out!
If you would like to use ES6/7 in your projects without having to worry about compatibility, you can use Node and Babel CLI
~ npm init
~ npm install --save-dev babel-cli
~ npm install --save-dev babel-preset-es2015
scripts
folder to store your .js
files, and then a dist/scripts
folder where the transpiled fully compatible files will be stored..babelrc
file in the root folder of your project, and write this on it{
"presets": ["es2015"]
}
package.json
file (created when you ran npm init
) and add the build
script to the scripts
property:{
...
"scripts": {
... ,
"build": "babel scripts --out-dir dist/scripts"
},
...
}
~ npm run build
For more complex projects you might want to take a look at Gulp or Webpack