使用babel转储到es3(Safari兼容) [英] Using babel to transpile to es3 (safari compliant)

查看:778
本文介绍了使用babel转储到es3(Safari兼容)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的babel。

我这样设置:

.babelrc:

  {
预设值:[es2015,es2017]
}

gulpfile:

  gulp.task('default',function(){
return gulp.src(['src / ** / *。js','!src / ** / 3rd / *'])
.pipe(babel())
.pipe(gulp.dest('dist'));
});

然而,这似乎正在编译为es5,Safari并未完全支持。 b
$ b

有没有设定目标的方法?所以它可以编译成ES3?

解决方案

不,Babel不支持转译到ES3。

您的选择是:


  1. 编译为ES5,然后使用 ES5 shim 使用另一个转译器。 Google Closure编译器 TypeScript 都支持ES6作为输入,ES3作为输出。

  2. >注意: Babel生成的ES5代码可能不适用于所有浏览器,因为它可能包含ES5中不存在的功能(请参阅注意事项以获取更多信息)。换句话说,既然您的目标是旧版浏览器,您还需要 Babel polyfill 以及ES5垫片。

    I am new to babel.

    I set it up like this:

    .babelrc:

    {
        "presets": ["es2015", "es2017"]
    }
    

    gulpfile:

    gulp.task('default', function() {
        return gulp.src(['src/**/*.js', '!src/**/3rd/*'])
            .pipe(babel())
            .pipe(gulp.dest('dist'));
    });
    

    However this seems to be compiling to es5 which is not fully supported in Safari.

    Is there a way to set target? So it can compile to ES3?

    解决方案

    No, Babel does not support transpiling to ES3.

    Your options are:

    1. Compile to ES5 and then use ES5 shim.

    2. Use a different transpiler. Google Closure Compiler and TypeScript both support ES6 as input and ES3 as output.

    Note: The "ES5" code that Babel produces may not work in all browsers, as it may include features not present in ES5 (see caveats for more info). In other words, since you're targeting even older browsers, you'll also need Babel polyfill as well as ES5 shim.

    这篇关于使用babel转储到es3(Safari兼容)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆