使用babel将es6转换为es5,然后与Browserify捆绑 [英] Convert es6 to es5 using babel then Bundle with Browserify
问题描述
我正在使用诸如import和classes之类的es6功能,现在我了解到该浏览器不支持导入功能,我在在此处阅读一个>.我需要将es6代码转换为es5,之后需要使用Browserify或gulp,webpack,browserify等将它们捆绑在一起.现在的问题是这样的:代码每次都会更改,我想检查一下结果,我想在每次查看结果之前都需要重复此过程吗?
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?
推荐答案
是的,每当您更改某些内容时,都需要重新构建它.看一下 watchify ,对于更复杂的项目,您可以考虑使用
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 ] ]
这篇关于使用babel将es6转换为es5,然后与Browserify捆绑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!