- 我正在使用Webpack和babel的最新版本。
- 当我尝试在IE11上运行代码时,出现指针函数的语法错误。
- 我检查了该块,并且它仅来自“ react-html-parser”。
- 该代码在chrome上正常工作,因为它支持指针功能。
- 我觉得babel不在node_modules上运行,因为我可以看到 指针函数将从src中删除,但不会从node_modules中删除。 (令人惊讶的是,material-ui和其他node_module似乎没有指针功能。)
以下是我的webpack配置:
{
mode: 'production',module: {
rules: [
{
test: /\.(eot|jsx?)$/,// Transform all .js and .jsx files required somewhere with Babel
exclude: /node_modules/,use: {
loader: 'babel-loader',options: options.babelQuery
}
},{ //tried adding explicitly! doesn't work
test: /\.(eot|jsx?)$/,// Transform all .js and .jsx files required somewhere with Babel
include: /node_modules\/react-html-parser\/.*/,use: {
loader: 'babel-loader'
}
}]},// In production,we skip all hot-reloading stuff
entry: [
require.resolve('react-app-polyfill/ie11'),path.join(process.cwd(),'src/index.js')
],// Utilize long-term caching by adding content hashes (not compilation hashes) to compiled assets
output: {
filename: '[name].[chunkhash].js',chunkFilename: '[name].[chunkhash].chunk.js'
},optimization: {
minimize: true,minimizer: [
new TerserPlugin({
terserOptions: {
warnings: false,compress: {
comparisons: false
},parse: {},mangle: true,output: {
comments: false,ascii_only: true
}
},parallel: true,cache: true,sourceMap: true
})
],nodeEnv: 'production',sideEffects: true,concatenateModules: true,runtimeChunk: 'single',splitChunks: {
chunks: 'all',maxInitialRequests: 40,minSize: 0,cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,name(module) {
const packageName = module.context.match(
/[\\/]node_modules[\\/](.*?)([\\/]|$)/
)[1];
return `npm.${packageName.replace('@','')}`;
}
}
}
}
},plugins: [
new Copyplugin([{ from: 'bin/conf',to: '' }]),// Minify and optimize the index.html
new HtmlWebpackPlugin({
template: 'src/index.html',minify: {
removeComments: true,collapseWhitespace: true,removeRedundantAttributes: true,useShortDoctype: true,removeEmptyAttributes: true,removeStyleLinkTypeAttributes: true,keepClosingSlash: true,minifyJS: true,minifyCSS: true,minifyURLs: true
},inject: true
}),new CompressionPlugin({
algorithm: 'gzip',test: /\.js$|\.css$|\.html$/,threshold: 10240,minRatio: 0.8
}),new HashedmoduleIdsPlugin({
hashFunction: 'sha256',hashDigest: 'hex',hashDigestLength: 20
})
],performance: {
assetfilter: assetfilename =>
!/(\.map$)|(^(main\.|favicon\.))/.test(assetfilename)
}
});