1. 安装
cnpm install html-webpack-plugin --save-dev
2. webpack.config.js中使用
const htmlWebpackPlugin = require('html-webpack-plugin');
配置多个html页面
/* * 配置多个入口文件 * */ entry: { index: './src/default/js/index.js', about: './src//about/js/index.js', course: './src/course/js/index.js' },
/* * 配置html-webpack-plugin插件(配置多个html文件) * template:模板路径 * filename:输出文件,可以是路径 * minify.removeComments:打包后是否删除参数 * minify.collapseWhitespace:打包后是否删除空格(压缩) * hash * chunks:包含的文件数组 * */ new htmlWebpackPlugin({ template: './src/index.html', filename: 'index.html', minify: { collapseWhitespace: true }, hash: true, chunks: ['index'] }), new htmlWebpackPlugin({ template: './src/about/index.html', filename: 'about/index.html', minify: { collapseWhitespace: true }, hash: true, chunks: ['about'] }), new htmlWebpackPlugin({ template: './src/course/index.html', //编译后路径是:dist/course/index.html filename: 'course/index.html', minify: { collapseWhitespace: true }, hash: true, chunks: ['course'] }),