使用 babel 转译为 es3(兼容 safari) [英] Using babel to transpile to es3 (safari compliant)

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

问题描述

我是 babel 的新手.

I am new to babel.

我是这样设置的:

.babelrc:

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

gulpfile:

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

然而,这似乎正在编译为 Safari 不完全支持的 es5.

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

有没有办法设置目标?那么它可以编译成 ES3 吗?

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

推荐答案

不,Babel 不支持转译到 ES3.

No, Babel does not support transpiling to ES3.

您的选择是:

  1. 编译为 ES5,然后使用 ES5 shim.

使用不同的转译器.Google Closure 编译器TypeScript 都支持 ES6 作为输入和 ES3 作为输出.

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

注意: Babel 生成的ES5"代码可能不适用于所有浏览器,因为它可能包含 ES5 中不存在的功能(请参阅 警告 了解更多信息).换句话说,由于您的目标是更旧的浏览器,因此您还需要 Babel polyfill以及 ES5 垫片.

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天全站免登陆