随着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
?有任何想法吗?