webpack的基本使用(四)---配置html-webpack-plugin

实现默认预览页面功能的步骤如下:
1.安装默认预览功能的包:html-webpack-plugin
npm install html-webpack-plugin -D
2.修改webpack.config.js文件,如下:
//导入包
const HtmlWebpackPlugin = require(“html-webpack-plugin”);
//创建对象
const htmlPlugin = new HtmlWebpackPlugin({
//设置生成预览页面的模板文件
template:"./src/index.html",
//设置生成的预览页面名称
filename:“index.html”
})
3.继续修改webpack.config.js文件,添加plugins信息:
module.exports = {

plugins:[ htmlPlugin ]
}
4.终端执行"npm run -dev"
5.然后访问 http://localhost:8080, 就可以看到你预览页面了

猜你喜欢

转载自blog.csdn.net/qq_41176055/article/details/105485419