RichErp - html-webpack-plugin 用法
复制自网络:
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
devtool:'eval-source-map',
devServer:{
inline:true,
colors:true,
port:8080,
contentBase:__dirname + '/public'
},
entry:{
index:__dirname + '/app/index.js',
main:__dirname + '/app/main.js'
},
output:{
path:__dirname + '/public', //通过HtmlWebpackPlugin插件生成的html文件存放在这个目录下面
filename:'/js/[name].js' //编译生成的js文件存放到根目录下面的js目录下面,如果js目录不存在则自动创建
},
plugins:[
new HtmlWebpackPlugin({
title:'自动生成自定义标题',//如果使用了模板,就使用模板里的title,这里的title设置会失效,哪怕模板里的title为空
template:__dirname + '/public/tempIndex.html',//需要编译的模板,可以是jade等第三方模板引擎也可以说纯html页面
filename:'demo.html',//最终生成的文件名,默认是index.html
hash:true,//是否给所有包含的js、css文件后面添加hash值,可以用来清除缓存,但好像不是很管用
inject:true,// | 'head' | 'body' | false ,注入所有的资源到特定的 template 或者 templateContent 中,如果设置为 true 或者 body,所有的 javascript 资源将被放置到 body 元素的底部,'head' 将放置到 head 元素中。
chunks:['index'] //指定生成的文件demo.hmtl需要包括entry里的哪些入口文件(这里是index,main.js不会引入),不设置的话所以入口js文件都会被引入进来
}),
new webpack.HotModuleReplacementPlugin() //热加载
]
}
浙公网安备 33010602011771号