【问题标题】:how can I use babel polyfill to support all IE11 issues with gulp如何使用 babel polyfill 支持 gulp 的所有 IE11 问题
【发布时间】:2019-05-19 06:03:25
【问题描述】:

我一直在通过为 transform-object-assignarray-includes 添加插件来拼凑对 IE11 的支持,现在我在使用 for of 循环时遇到符号错误。除了一次解决一个问题,我是否可以将 babel polyfill 应用到我的下面的构建中并在未来证明它?

我已经阅读了几个相关的问题,但仍然不清楚如何将 babel-polyfill 放入下面的 gulp 构建中:

return gulp.src(input)  // Grab the input files
        .pipe($.babel({
            presets: ['es2015'], // transform ES6 to ES5 with Babel
            plugins: ['transform-object-assign','array-includes']

        }))
        .pipe($.concat(outputFile))
        .pipe($.uglify({
            compress: {
                drop_debugger:  true
            }
        }))
        .pipe(gulp.dest(paths.output))  // Output file destination
        .pipe($.connect.reload());
}

【问题讨论】:

    标签: javascript gulp internet-explorer-11 babeljs polyfills


    【解决方案1】:

    编辑

    我注意到 babel-polyfill 和 IE 存在问题,当我恢复到这个 npm 包 "babel-polyfill": "6.5.0" 一切开始正常工作

    /编辑

    你在用browserify吗?您还需要babel-polyfill 和插件['transform-es2015-classes', { loose: true }]]

    这是我的 IE 与 babel6 兼容性的 gulp 任务:

    gulp.task('compile', () => {
        browserify('./js/script.js', { debug: true })
        .add(require.resolve('babel-polyfill'))
        .transform(babelify.configure({presets: ['es2015'], plugins:['transform-es2015-classes', { loose: true }]]}))
        .bundle()
        .on('error', util.log.bind(util, 'Browserify Error'))
        .pipe(source('script.js'))
        .pipe(buffer())
        .pipe(sourcemaps.init({loadMaps: true}))
        .pipe(uglify({ mangle: false }))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('./build'));
      });
    

    【讨论】:

    猜你喜欢
    • 2021-03-12
    • 2015-10-09
    • 1970-01-01
    • 1970-01-01
    • 2016-11-21
    • 1970-01-01
    • 2017-11-26
    • 2019-07-02
    • 1970-01-01
    相关资源
    最近更新 更多