我正在编译我的应用程序,并尝试使其支持IE。但是,polyfill在我的供应商填充中留下了const语句,这会破坏IE。
我的配置有问题吗?
Webpack:
{
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"
}
}
]
]
}
编辑:对不起,我忘了包括我快乐的加载器配置,它确实通过babel-loader运行我的代码:
let plugins = [
new HardSourceWebpackPlugin(),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new HappyPack({
loaders: ["babel-loader"]
}),
new LiveReloadPlugin({
hostname: "localhost"
})
];
答案 0 :(得分:1)
安装babel-loader
并尝试以下配置:
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
}
答案 1 :(得分:0)
babel-polyfil对此进行了介绍。升级到> 7.4.4进行修复。