Although support for ES2015 (formerly ES6) is improving in modern browsers, the majority do not yet support the full set of features. To benefit from the awesomeness of the new ES2015 syntax while keeping backwards compatibility with Polymer's supported browsers, you'll need to transpile your JS code from ES2015 to ES5
+ .pipe($.if('*.html', $.crisper({scriptInHead:false}))) // Extract JS from .html files
+ .pipe($.if('*.js', $.babel({
+ presets: ['es2015']
+ })))
+ .pipe($.sourcemaps.write('.'))
+ .pipe(gulp.dest('.tmp/'))
+ .pipe(gulp.dest(dist()));
+ });
```
This task will transpile all JS files and inline JS inside HTML files and also generate sourcemaps. The resulting files are generated in the `.tmp` and the `dist` folders
[Crisper](https://github.com/PolymerLabs/crisper) extracts JavaScript that's inline to HTML files (such as imports). We need this as Babel does not support transpiling HTML files such as `<script>` tags directly
Note: At the time of writing Crisper does not generate the sourcemaps. Your app will work but you won't get sourcemaps for files transformed by Crisper. Relevant issues:
- In the `optimizeHtmlTask` function remove the `searchPath` attribute since all assets should be found under the `dist` folder and we want to make sure we are not picking up duplicates and un-transpiled JS files:
```patch
var optimizeHtmlTask = function (src, dest) {
- var assets = $.useref.assets({searchPath: ['.tmp', 'app', 'dist']});
+ var assets = $.useref.assets();
```
## Configure linters for ES2015
- Enable ES2015 support in JSCS. Add `"esnext": true` to the `.jscsrc` file:
- Enable ES2015 support in JSHint. Add `"esnext": true` to the `.jshintrc` file:
```patch
{
+ "esnext": true,
"node": true,
"browser": true,
```
## Optional - When using shadow-dom instead shady-dom
Place this configuration ([Read more](https://www.polymer-project.org/1.0/docs/devguide/settings.html)) in a separate file like `scripts/polymer-settings`