Babel 7不会将CONST更改为VAR [英] Babel 7 doesn't change CONST to VAR
本文介绍了Babel 7不会将CONST更改为VAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Safari版本< = 9时遇到问题. Babel似乎没有用var代替const.
I have problem with Safari version <= 9. Babel doesn't seem to replace const with var.
我在控制台中收到此错误:
I get this error in console:
意外的关键字"const".在严格模式下不支持const声明.
我尝试使用@ babel/preset-stage-0,但babel删除了它.
I tried using @babel/preset-stage-0 but babel removed it.
这是我的应用配置:
.babelrc
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-transform-object-assign"
]
}
webpack.config.js
webpack.config.js
const path = require("path");
const webpack = require("webpack");
const componentName = "contact-captain";
const publicFolderRelativePath = "../../../../public/js";
const ignorePlugin = new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/);
module.exports = {
// devtool: "source-map",
output: {
path: path.resolve(__dirname, publicFolderRelativePath),
filename: `${componentName}.js`
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
},
plugins: [
ignorePlugin
]
};
推荐答案
您尝试配置preset-env
吗?
您可以在此处找到浏览器列表: https://github.com/browserslist/browserslist
did you try to configure preset-env
?
you can find the browsers list here: https://github.com/browserslist/browserslist
可能需要在列表中添加Safari 8
...
probably need to add Safari 8
in your list...
["@babel/preset-env", {
"targets": {
"browsers": ["last 2 versions"],
}
}]
这篇关于Babel 7不会将CONST更改为VAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文