1.npm install--save-dev mini-css-extract-plugin
2 webpack.config.js文件配置
const MiniCssExtractPlugin=require("mini-css-extract-plugin");
module.exports={
optimization:{
splitChunks:{
cacheGroups:{
styles: {
name:'styles',
test:/\.css$/,
chunks:'all',
enforce:true
}
}
}
},
plugins:[
newMiniCssExtractPlugin({filename:"[name].css",})
],
module:{
rules:[
{
test:/\.css$/,
use:[MiniCssExtractPlugin.loader, "css-loader"]
}
]
}
}