这篇文章主要介绍了html-webpack-plugin使用,详解本文给大家介绍的详解非常详细,对大家的详解(jie)学习或工作具有一定的参考借鉴价值,需要的朋友可以参(can)考下
最近在react项目中(zhong)初次用到了html-webapck-plugin插件,用到该插件的详解两个主要作用:

为html文件中引入的外部资源如script、link动态添加每(mei)次(ci)compile后的详解hash,防止引用缓存的详解外部文件问(wen)题

可以(yi)生成创建html入口文件,比如单页面(mian)可以(yi)生成一个html文件入口,详解配置N个html-webpack-plugin可以生成N个页面入口

1、详解安装
cnpm i webpack-plugin -D
2、详解(jie)在webpack.config.json中引用
const path = require('path')
const htmlWebpackPlugin = require('html-webpack-plugin') //第一步
module.exports = {
entry: path.join(__dirname,详解 './src/main.js'),
output: {
path: path.join(__dirname, './dist'),
filename: 'bundle.js',
},
mode: 'development',
devServer: {
open='open': true,
port: 8080,
hot: true,
contentBase: 'src'
},
plugins: [
new htmlWebpackPlugin({ //第二步
template: path.join(__dirname, './src/index.html'), //指定生成(cheng)模板的路径
filename: 'index.html' //指定生成页面的名称
})
]
}
3、html-webpack-plugin的详解作用
二、详解自动为指定模板文件(jian)添加bundle.js文件
总结
来源:脚本之家(jia)
链接:https://www.jb51.net/web/745178.html
电话:19974869549
网 址:http://1bye.net/
邮 箱:31994032@qq.com
地 址:上海市黄浦66号