HtmlWebpackPlugin 报错
来源:4-12 通用操作提示页开发
梅村
2017-07-11
<title><%= htmlWebpackPlugin.options.title%>--happymmall电商平台</title>
我运动 npm run dev 的时候 报
ERROR in Template execution failed: ReferenceError: HtmlWebpackPlugin is not defined
这个错
我的webpack.config.js
//====================================
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var HtmlWebpackPlugin = require('html-webpack-plugin');
//环境变量的配置 dev /online
var WEBPACK_ENV = process.env.WEBPACK_ENV || 'dev';
//获取html webpack-plugin参数的方法
var getHtmlConfig=function (name,title) {
return{
template : './src/view/'+name+'.html',
filename : 'view/'+name+'.html',
title : title,
inject : true,
hash :true,
chunks :['common',name]
};
}
var config= {
entry:{
'common':['./src/page/common/index.js'],
'index':['./src/page/index/index.js'],
'login':['./src/page/login/index.js'],
'result':['./src/page/result/index.js']
},
output:{
path:'./dist',
publicPath:'/dist',
filename:'js/[name].js'
},
externals:{
'jquery':'window.jQuery'
},
module:{
loaders:
[
{test:/\.css$/,loader:ExtractTextPlugin.extract("style-loader","css-loader")},
{test:/\.(gif|png|jpg|woff|svg|eot|ttf)\??.*$/,loader:'url-loader?limit=100&name=resource/[name].[ext]'},
{test:/\.string$/,loader:'html-loader'}
]
},
resolve:{
alias:
{
node_modules :__dirname + '/node_modules',
util :__dirname + '/src/util',
page :__dirname + '/src/page',
service :__dirname + '/src/service',
image :__dirname + '/src/image',
}
},
plugins:[
//独立通用模块
new webpack.optimize.CommonsChunkPlugin({
name : 'common',
filename : 'js/base.js'
}),
//把css单独打包到文件里
new ExtractTextPlugin("css/[name].css"),
//html 模板处理
new HtmlWebpackPlugin(getHtmlConfig('index','首页')),
new HtmlWebpackPlugin(getHtmlConfig('login','用户登录')),
new HtmlWebpackPlugin(getHtmlConfig('result','操作结果'))
]
};
if('dev' === WEBPACK_ENV)
{
config.entry.common.push('webpack-dev-server/client?http://localhost:8801/');
}
module.exports =config;
1回答
-
Rosen
2017-07-11
是不是哪个文件改完没保存?不是的话提供下报错的位置
012017-07-11
相似问题