隨着CommonsChunkPlugin
我現在有我的代碼分成:的WebPack 2:廠商,共同和具體捆綁
vendors.js
common.js
page-1.js
page-2-authenticated.js
page-3-authenticated.js
於是就page-1.html
我加載以下腳本:
<script src="vendors.js" />
<script src="common.js" />
<script src="page-1.js" />
它工作正常並且page-1.js
,page-2-authenticated.js
和page-3-authenticated.js
中的所有共享代碼被捆綁到common.js
中。
正如你所看到的,我的應用程序需要用戶登錄page-2-authenticated.html
和page-3-authenticated.html
。但是,page-2-authenticated.js
和page-3-authenticated.js
中的共享代碼也捆綁到common.js
中。 。但我不希望打擾誰沒有登錄的用戶,當你登錄的是僅用於代碼
所以對於page-2-authenticated.html
我想有:
<script src="vendors.js" />
<script src="common.js" />
<script src="common-authenticated.js" /> // Shared code for authenticated users
<script src="page-2-authenticated.js" />
但是,當我在common-authenticated.js
中導出測試變量並將其導入page-2-authenticated.js
和page-3-authenticated.js
時,此共享代碼仍然捆綁到common.js
中。而common-authenticated.js
是空的(只是一些webpackJsonp([12],[],[85]);
)。
我有以下的WebPack 2配置:
entry: {
vendors: ['react'],
common: 'index.js',
'common-authenticated': 'common-authenticated.js',
'page-1': 'page-1.js',
'page-2-authenticated': 'page-2-authenticated.js',
'page-3-authenticated': 'page-3-authenticated.js'
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
// The order of this array matters
names: ['common', 'vendors'],
minChunks: 2
})
]
問題:如何綁定特定的代碼爲common-authenticated.js
?有任何想法嗎?