安装
npm install html-webpack-plugin -D
修改webpack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin');//导入插件
const path = require('path');
//创建插件实例对象
const htmlPlugin = new HtmlWebpackPlugin({
template:'./src/index.html',//指定显示首页
filename: 'index.html'//指定名称,该文件存于内存中,目录中并不显示
})
module.exports = {
mode: 'development',
entry: path.join(__dirname, './src/index.js',
output: {
path: path.join(__dirname, './dist'),
filename: 'bundle.js'
},
plugins: [htmlPlugin]//plugins数组是webpack打包时用到的插件列表
};
执行
npm run dev