亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

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都有錯誤

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>


正在回答

14 回答

<script type="text/javascript">
? ?<%=
? ? ? ?compilation.assets[htmlWebpackPlugin.files.chunks.main.entry.substr(htmlWebpackPlugin.files.publicPath.length)].source()
? ?%>
</script>

在head中插入這段代碼也不會生成b.html和c.html怎么辦

0 回復 有任何疑惑可以回復我~

確實需要刪除才可以

0 回復 有任何疑惑可以回復我~

遇到同樣的問題!如果 index.html引用了js,需要刪除,注釋掉沒有用。

9 回復 有任何疑惑可以回復我~
#1

慕粉4061747

通過刪除解決了問題。為什么注釋掉沒用?是webpack打包時會讀注釋內容嗎?
2017-04-11 回復 有任何疑惑可以回復我~
#2

米斯特teng

剛剛遇到相同問題,刪除掉之前的script解決了,但為什么注釋掉沒有用,同問
2017-06-28 回復 有任何疑惑可以回復我~

inject:'body'改成inject:false,不要自動向index.html中插入js,然后在b和c頁面的的插件配置中,chunks要引入'main',因為你的index.html有個直接引用的js,調用了 main.entry。然后加上excludeChunks:['a','c']和excludeChunks:['a','b'],排除掉不需要的chunk,就OK了

5 回復 有任何疑惑可以回復我~
首頁上一頁12下一頁尾頁

舉報

0/150
提交
取消

Cannot read property 'entry' of undefined

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號