const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MinniCssexarctPlugin = require('mini-css-extarct-plugin')
module.exports = {
//入口
entry: {
index: './src/js/index.js',
login: './src/js/login.js',
},
//输出
output: {
//文件名
filename: '[name].js',
//路径:绝对路径
path: path.resolve(__dirname, './dist'),
// 每次打包先清楚dist文件夹
clean: true,
},
//资源管理 加载器
module: {
//资源的匹配的规则
rules: [
{
text: '/\.css$/',
use: [
MinniCssexarctPlugin.loader,
'css-loader',
],
generator: {
filename: 'css/[name].css',
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
inject: 'body',
filename: 'html/index.html',
chunks: ["index"]
}),
new HtmlWebpackPlugin({
template: './src/login.html',
inject: 'body',
filename: 'html/login.html',
chunks: ["login"]
}),
new MinniCssexarctPlugin(),
],
//模式:开发模式,生产模式
mode: "development",
}
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"css-loader": "^6.7.3",
"html-webpack-plugin": "^5.5.0",
"mini-css-extract-plugin": "^2.7.2",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
}
}
[webpack-cli] Failed to load 'E:\学习\js\test\webpack.config.js' config
[webpack-cli] Error: Cannot find module 'mini-css-extarct-plugin'
插件报错代码复制出来发给我