简体   繁体   English

我如何使用babel polyfill支持gulp的所有IE11问题

[英]how can I use babel polyfill to support all IE11 issues with gulp

I've been piecing together support for IE11 by adding plugins for transform-object-assign and array-includes and now I'm getting a symbol error for using for of loops. 通过添加用于transform-object-assignarray-includes插件,我一直在拼凑对IE11的支持,现在由于使用for of循环而出现符号错误。 Instead of just tackling them one at a time, is it possible for me to work babel polyfill into my build below and future proof it? 除了一次解决一个问题,我还可以在下面的构建中使用babel polyfill并进行未来验证吗?

I've read several related questions but still am not clear on how I'd fit babel-polyfill into the gulp build below: 我已经阅读了几个相关的问题,但是仍然不清楚如何将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());
}

Edit 编辑

I noticed an issue with babel-polyfill and IE, when i reverted to this npm package "babel-polyfill": "6.5.0" everything started working normally 我注意到babel-polyfill和IE出现问题,当我恢复到此npm软件包“ babel-polyfill”:“ 6.5.0”时,一切开始正常运行

/Edit /编辑

Are you using browserify? 您在使用browserify吗? Also you'll need the babel-polyfill and the plugin ['transform-es2015-classes', { loose: true }]] 另外,您还需要babel-polyfill和插件['transform-es2015-classes', { loose: true }]]

heres my gulp task for IE compatibility with babel6: 这是我与bel6兼容的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'));
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM