1. 安裝 html-webpack-plugin
npm install html-webpack-plugin --save-dev
2. 在webpack.config.js中配置
const htmlWebpackPlugin=require('html-webpack-plugin')
module.exports={
//...code
plugins:[
new htmlWebpackPlugin({
template:"./src/index.html",
filename:"index.html",//生成的文件名
minify:{
minimize:true,//是否打包為最小值
removeAttrbuteQuotes:true,//去除引號
removeComments:true,//去掉注釋
collapseWhitespace:true,//去掉空格
minifyCss:true,//壓縮css
removeEmptyElements:false,//清理內容為空的元素
},
chunks: ['base', 'index'], //引入對應的js(對應(entry)中的入口文件)
hash:true//引入產出的資源時加上哈希避免緩存
})
]
}
3. 使用方法
直接啟動webpack進行項目打包即可