一、运行 npm install html-webpack-plugin –D 命令,安装生成预览页面的插件
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/4cc0e8c006ce2a9617b7977428d87e5b.png)
二、 修改 webpack.config.js 文件头部区域,配置如下信息:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
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]
}
三、运行 npm run dev
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/bb966dc2e586699a67a777015b32dd65.png)
四、访问http://localhost:8080/,预览页面为index.html的页面