随着CommonsChunkPlugin
我目前将我的代码分为:
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
andpage-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
?有任何想法吗?