使用 babel 和 laravel-mix 将 ES6 转换为 ES2015
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52352701/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert ES6 to ES2015 using babel and laravel-mix
提问by Bereket Gobeze
I have ES6 JavaScript code in my Vue components. In order to support IE 11 I need to convert it to ES5 code using babel and laravel-mix. How do I do that?
我的 Vue 组件中有 ES6 JavaScript 代码。为了支持 IE 11,我需要使用 babel 和 laravel-mix 将其转换为 ES5 代码。我怎么做?
Here is my webpack.mix.js file.
这是我的 webpack.mix.js 文件。
let mix = require('laravel-mix');
mix.js('resources/assets/js/app.js', 'public/js')
.js('resources/assets/js/admin-app.js', 'public/js')
回答by Darryl E. Clarke
There's a mix.babel()
command that can handle this.
有一个mix.babel()
命令可以处理这个问题。
It's identical to mix.scripts()
so it requires a little more legwork. I cheat and do this and then serve the es5.js to IE:
它与 相同,mix.scripts()
因此需要更多的跑腿工作。我作弊并执行此操作,然后将 es5.js 提供给 IE:
mix.js('resources/assets/js/app.js', 'public/js')
.babel('public/js/app.js', 'public/js/app.es5.js')
.sass('resources/assets/sass/app.scss', 'public/css');
回答by R0bertinski
The code is not 100% correct: babel first argument should be an array:
代码不是 100% 正确:babel 第一个参数应该是一个数组:
mix.js('resources/assets/js/app.js', 'public/js')
.babel(['public/js/app.js'], 'public/js/app.es5.js')
.sass('resources/assets/sass/app.scss', 'public/css');