I’ve been interested in using ECMAScript 6. I like how it simplifies creating prototypes (i.e. the class keyword) and the built in module support. I found a tool called Babel that translates ES6 to readable ES5 code that runs in the browser. It’s easy to plugin into browserify in a Node project. I wanted to start using it in Grails so I created a new asset-pipeline plugin called es6to5-asset-pipeline. (It’s called es6to5 because when I started it, babel was called 6to5).
Usage is simple:
- Include the asset-pipeline and es6to5-asset-pipeline plugins in your project
The plugin will run each file thru babel, wrap the results in an IIFE and convert the CommonJS style requires and exports into something that will work in the browser.
I was able to get my plugin to process the import statements; so instead of this ES6 code:
You can leave out the require and avoid the duplication:
There is more documentation available on github. Please give it a try and let me know what you think. So far I’ve only used it on a few small personal projects so I’d love to get some folks testing it out.