Cannot read property 'entry' of undefined
var?htmlWebpackPlugin?=?require('html-webpack-plugin'); //commom.js的模塊化輸出 module.exports={ entry:{ main:'./src/script/main.js', a:?'./src/script/a.js', b:?'./src/script/b.js', c:?'./src/script/c.js' },//入口文件 output:{ path:'./dist', filename:'js/[name]-[chunkhash].js', //?publicPath:"http://cdn.com/" }, plugins:[ new?htmlWebpackPlugin({ filename:'a.html', template:'index.html', title:"webapck?is?a", inject:'body', chunks:['main','a'] ?}), new?htmlWebpackPlugin({ filename:'b.html', template:'index.html', title:"webapck?is?b", inject:'body', chunks:['b'] }), new?htmlWebpackPlugin({ filename:'c.html', template:'index.html', title:"webapck?is?c", inject:'body', chunks:['c'] }) ] };
除了a頁面可以生成,b.html和c.html都有錯(cuò)誤
Html?Webpack?Plugin: <pre> ??TypeError:?Cannot?read?property?'entry'?of?undefined ?? ??-?index.html:17237? ????D:/dwf/study/webpacklearn/index.html:17237:42 ?? ??-?index.html:17240?module.exports ????D:/dwf/study/webpacklearn/index.html:17240:3 ?? ??-?index.js:265? ????[webpacklearn]/[html-webpack-plugin]/index.js:265:16 ?? ??-?util.js:16?tryCatcher ????[webpacklearn]/[bluebird]/js/release/util.js:16:23 ?? ??-?promise.js:512?Promise._settlePromiseFromHandler ????[webpacklearn]/[bluebird]/js/release/promise.js:512:31 ?? ??-?promise.js:569?Promise._settlePromise ????[webpacklearn]/[bluebird]/js/release/promise.js:569:18 ?? ??-?promise.js:606?Promise._settlePromiseCtx ????[webpacklearn]/[bluebird]/js/release/promise.js:606:10 ?? ??-?async.js:138?Async._drainQueue ????[webpacklearn]/[bluebird]/js/release/async.js:138:12 ?? ??-?async.js:143?Async._drainQueues ????[webpacklearn]/[bluebird]/js/release/async.js:143:10 ?? ??-?async.js:17?Immediate.Async.drainQueues ????[webpacklearn]/[bluebird]/js/release/async.js:17:14 ?? </pre>
2017-06-05
<script type="text/javascript">
? ?<%=
? ? ? ?compilation.assets[htmlWebpackPlugin.files.chunks.main.entry.substr(htmlWebpackPlugin.files.publicPath.length)].source()
? ?%>
</script>
在head中插入這段代碼也不會(huì)生成b.html和c.html怎么辦
2017-05-12
確實(shí)需要?jiǎng)h除才可以
2017-03-25
遇到同樣的問題!如果 index.html引用了js,需要?jiǎng)h除,注釋掉沒有用。
2017-03-15
inject:'body'改成inject:false,不要自動(dòng)向index.html中插入js,然后在b和c頁面的的插件配置中,chunks要引入'main',因?yàn)槟愕膇ndex.html有個(gè)直接引用的js,調(diào)用了 main.entry。然后加上excludeChunks:['a','c']和excludeChunks:['a','b'],排除掉不需要的chunk,就OK了