1 引入相关打包压缩插件:html-webpack-plugin
详细配置链接: https://www.npmjs.com/package/html-webpack-plugin
PS D:\Webpack\03-webpackcss> npm i -D html-webpack-plugin
2.webpack.config.js中引入相关插件,在plugin配置中进行实例化
const HtmlWebpackPlugin = require('html-webpack-plugin')
new HtmlWebpackPlugin()
3.在终端运行webpack命令, 就可以生成HTML文件index.html,并可以在html中加载所有打包资源
该插件还可以:
(1)可指定html模板,在plugin中设置template,
new HtmlWebpackPlugin({
// 生成html的模板
template: 'index.html'
})
需要特别留意html模板的所在文件的绝对路径,否则会报错找不到
1 ERROR in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details)
//文件路径错误报错