【问题标题】:Grunt babel is not transforming arrow functions for IEGrunt babel 没有为 IE 转换箭头函数
【发布时间】:2018-11-17 17:47:16
【问题描述】:

如何在旧版 grunt 构建中包含 babel 和 browserify 以转换 es6 代码?

【问题讨论】:

  • 您是否尝试过通过
  • @RobC 是的,我确实在 index.html 中包含了 babel-polyfill 作为 cdnjs 脚本标签。
  • 在您的.babelrc 中,Babel 预设 应定义为{ "presets": ["es2015-ie"] } 而不是plugins - 如图所示here
  • 我注意到您在 package.json 中将 babel-plugin-transform-es2015-arrow-functions 列为 devDependencies。我不确定您为什么需要它,但是尝试将其作为plugin 添加到您的.babelrc 中,因此它显示为:{"presets": ["es2015-ie"], "plugins": ["transform-es2015-arrow-functions"]} (更多信息here
  • 可能还值得尝试用@babel/preset-env 替换babel-preset-env 包并专门使用.babelrc 中的targets: {...} 属性来定位IE11 - 有关此here 的更多信息。跨度>

标签: javascript angularjs internet-explorer gruntjs babeljs


【解决方案1】:

试试这个, 在gruntfile.js 中添加以下代码并注意它需要autopolyfiller 依赖:

grunt.initConfig({
autopolyfiller: {
    latest_browsers_and_ie: {
        options: {
            browsers: ['last 2 version', 'ie 8', 'ie 9', 'ie 11']
        },
        files: {
            'www/file_with_all_polyfills.js': ['your/js/**/*.js']
        }
    }
}
});

【讨论】:

    猜你喜欢
    • 2016-07-06
    • 2019-03-20
    • 1970-01-01
    • 1970-01-01
    • 2019-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多