webpack插件:
npm install clean-webpack-plugin -D
在webpack.config.js中导入:
const {CleanWebpackPlugin} = require(“clean-webpack-plugin”);
在webpack.config.js中module.exports中添加plugins配置:
plugins:[
new CleanWebpackPlugin()
];
npm install html-webpack-plugin -D
在webpack.config.js中导入:
const HtmlWebpackPlugin = require("html-webpack-plugin");
在webpack.config.js中module.exports中添加plugins配置:
plugins:[
new CleanWebpackPlugin(),
new HtmlWebpackPlugin()
];
自定义html:
在webpack.config.js中module.exports中添加plugins配置:
plugins:[
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template:"./public/index.html",
}),
];
自定义变量
在webpack.config.js中导入:
const {DefinePlugin} = require("webpack");
在webpack.config.js中module.exports中添加plugins配置:
plugins:[
new CleanWebpackPlugin(),
new HtmlWebpackPlugin(),
new DefinePlugin({
BASE_URL:"'./'"
})
];
npm install copy-webpack-plugin -D
在webpack.config.js中导入:
const CopyWebpackPlugin = require("copy-webpack-plugin");
在webpack.config.js中module.exports中添加plugins配置:
plugins:[
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template:"./public/index.html",
title:"陆之凡"
}),
new DefinePlugin({
BASE_URL:"'./'"
}),
new CopyWebpackPlugin({
//patterns匹配
patterns:[
{
from: "public",
//to: "build",
to: "./",
globOptions:{
ignore:[
"**/index.html"
]
}
}
]
}),
];
在webpack.config.js中module.exports中添加mode和devtool配置:
//设置模式
//development 开发阶段,会设置development
//production 准备打包上线的时候,设置production
mode:"development",
//设置source-map,建立js映射文件,方便调试代码和错误
devtool:"source-map",