Dell老师你好,我在进行按需加载的时候报错了
报错的提交: UnhandledPromiseRejectionWarning: Error: SplitChunksPlugin: You are trying to set a filename for a chunk which is (also) loaded on demand. The runtime can only handle loading of chunks which match the chunkFilename schema. Using a custom filename would fail at runtime. (cache group: vendors)
下面的是我的配置
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
module.exports = {
entry: {
main:'./src/index.js',
},
output: {
publicPath: './',
filename: '[name].js',
path: path.resolve(__dirname, '../dist')
},
plugins: [new HtmlWebpackPlugin({
template: './src/template.html'
}), new CleanWebpackPlugin()], // htmlwebpackplugins作用是会在打包结束之后自动生成一个html模板,并把打包生成的js文件自动引入到这个html文件中
optimization: { // Tree Shaking 的实现,作用是打包的时候不会打包没有引入的东西,想要实现这个功能还需要在packjson里面设置sideEffects: [''],同时在生产环境已经自动集成了这个功能
splitChunks: {
chunks: 'all',
minSize: 100,
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10,
filename: 'vendors.js'
},
default: {
priority: 2,
reuseExistingChunk: true,
filename: 'common.js'
},
}
}
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},{
test: /\.(jpg|png|gif)$/,
use: {
loader: 'url-loader',
options: {
name: '[name].[ext]',
outputPath: 'images/',
limit: 204800
},
},
}, {
test: /\.scss$/,
use: [
'style-loader', {
loader: 'css-loader',
options: {
importLoaders: 2, // 执行下面两个loader
// modules: true, // css 模块化
},
},
'sass-loader',
'postcss-loader']
}, {
test: /\.(eot|ttf|svg|woff)$/,
use: {
loader: 'file-loader'
},
}, {
test: /\.css/,
use: ['style-loader', 'css-loader', 'postcss-loader']
}]
},
}