# Add ES2015 support through Babel 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 This recipe focuses on adding an ES2015 to ES5 transpile step to Polymer Starter Kit's build pipeline using [BabelJS](https://babeljs.io/). ## Create a transpile gulp task - Install the gulp Babel, Sourcemap, Crisper plugins and Babel ES2015 preset: `npm install --save-dev gulp-babel gulp-sourcemaps gulp-crisper babel-preset-es2015` - Add the following gulp task in the `gulpfile.js` file: ```patch + // Transpile all JS to ES5. + gulp.task('js', function () { + return gulp.src(['app/**/*.{js,html}', '!app/bower_components/**/*']) + .pipe($.sourcemaps.init()) + .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 ` ```