我在title里設置了<title><%= HtmlWebpackPlugin.options.title %></title> 打包時提示HtmlWebpackPlugin未定義
<!DOCTYPE html>
<html>
<head>
?<meta charset="UTF-8">
?<title><%= HtmlWebpackPlugin.options.title %></title>
</head>
<body>
?
</body>
</html>
const path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin'); // 通過 npm 安裝
const webpack = require('webpack'); // 用于訪問內置插件
module.exports={
?entry:"./src/script/main.js",
?output:{
??path:path.resolve(__dirname, 'dist'),
??filename:"js/bundle.js"
?},
?plugins: [
??? new webpack.optimize.UglifyJsPlugin(),
??? new HtmlWebpackPlugin({
??? ?//打包后的文件的名字
??? ?filename:'index1.html',
??? ?//以index為模板
??? ?template:"index.html",
??? ?//把打包后的js 引入到 頭部還是尾部
??? ?inject:"body",
??? ?// 頁面可以得到
??? ?title:"awebsdfsdfs",
??? ?date:new Date(),
??? })
? ]
}
2018-02-27
解決了