How to use EcmaScript 6 features in Ionic?

I recently used a new data structure specification, not an array, where I didn’t want any duplicate values ​​to be saved, and it works without problems, but I wonder, I want to implement some of the new functions, such as let , class and const .

I also use the crosswalk plugin, if that matters.

Can someone tell me if I should avoid ES6 at the moment or if it should be used normally?

+6
source share
1 answer

Actually I went by myself on my own today, and I found this tutorial: http://labs.encoded.io/2015/06/22/use-es6-with-ionic/

StackOverflow recommends not just using links as answers, so I'm going to give my TL, DR, since this is not my own site, and I do not want to be held accountable for c / p.

Ionic uses Gulp, so install gulp -babel and gulp -plumber.

 npm install --save-dev gulp-babel gulp-plumber 

Add babel to gulpfile.js like this:

 //... var babel = require("gulp-babel"); var plumber = require("gulp-plumber"); var paths = { es6: ['./src/es6/*.js'], sass: ['./scss/**/*.scss'] }; gulp.task('default', ['babel', 'sass']); gulp.task("babel", function () { return gulp.src(paths.es6) .pipe(plumber()) .pipe(babel()) .pipe(gulp.dest("www/js")); }); //... gulp.task('watch', function() { gulp.watch(paths.es6, ['babel']); gulp.watch(paths.sass, ['sass']); }); //... 

Edit ionic.project :

 "gulpStartupTasks": [ "babel", "sass", "watch" ], 

For more information, refer to the original link - and with this I also say thanks to the author of this blog, as it also helped me.

+9
source

All Articles