Convert es6 to es5 using babel then Bundle with Br

2019-08-10 12:11发布

问题:

Im using es6 feature like import and classes , now i understand that the browser doesn't support import feature and i read here. that i need to convert the es6 code into es5 , and after it i need to bundle them using Browserify or gulp, webpack, browserify, etc. Now the question going like that: the code changes everytime and i want to check my results , do i need to repeat of this procedure everytime before i want to see the results?

回答1:

Yes, every time you change something you need to rebuild it unfortunately. Take a look at watchify or for more complex projects you might consider using grunt or any other task runner to automate the process.

// first install watchify, babelify and babel-preset-es2015
watchify script.js -o bundle.js -t [ babelify --presets [ es2015 ] ]