Webpack / Babel 未删除 "const"
Webpack / Babel not removing "const"
我正在转换我的应用程序并尝试让它支持 IE。然而,polyfill 在我的 vendor fill 中留下了一个 const 语句,这会破坏 IE。
我的配置有问题吗?
网页包:
{
mode: "production",
entry: {
app: ["whatwg-fetch", "@babel/polyfill", "./src/app/app.js"]
},
output: {
path: path.resolve(
__dirname,
"temp/" + envData.environment + "/app/js"
),
filename: "[name].bundle.js",
publicPath: "/"
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\/]node_modules[\/]/,
name: "vendor",
chunks: "initial"
}
}
}
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: "happypack/loader",
options: { babelrc: true, cacheDirectory: "./cache" }
}
]
}
}
Babelrc:
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"chrome": "55",
"ie": "8"
}
}
]
]
}
编辑:抱歉,我忘记包含我的 happy loader 配置,它通过 babel-loader 运行 我的代码:
let plugins = [
new HardSourceWebpackPlugin(),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new HappyPack({
loaders: ["babel-loader"]
}),
new LiveReloadPlugin({
hostname: "localhost"
})
];
安装 babel-loader
并尝试以下配置:
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
}
babel-polyfil介绍了这个。升级到 > 7.4.4 进行修复。
我正在转换我的应用程序并尝试让它支持 IE。然而,polyfill 在我的 vendor fill 中留下了一个 const 语句,这会破坏 IE。
我的配置有问题吗?
网页包:
{
mode: "production",
entry: {
app: ["whatwg-fetch", "@babel/polyfill", "./src/app/app.js"]
},
output: {
path: path.resolve(
__dirname,
"temp/" + envData.environment + "/app/js"
),
filename: "[name].bundle.js",
publicPath: "/"
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\/]node_modules[\/]/,
name: "vendor",
chunks: "initial"
}
}
}
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: "happypack/loader",
options: { babelrc: true, cacheDirectory: "./cache" }
}
]
}
}
Babelrc:
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"chrome": "55",
"ie": "8"
}
}
]
]
}
编辑:抱歉,我忘记包含我的 happy loader 配置,它通过 babel-loader 运行 我的代码:
let plugins = [
new HardSourceWebpackPlugin(),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new HappyPack({
loaders: ["babel-loader"]
}),
new LiveReloadPlugin({
hostname: "localhost"
})
];
安装 babel-loader
并尝试以下配置:
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
}
babel-polyfil介绍了这个。升级到 > 7.4.4 进行修复。