我有一些网站脚本。它们的设置如下:
<!-- This script is loaded on every page -->
<script src="bundle1.js"></script>
<!-- This script is only loaded on certain pages -->
<script src="bundle2.js"></script>
bundle1.js
和bundle2.js
都使用jQuery。我使用SplitChunksPlugin
,因此现在创建了第三个捆绑软件:common.bundle.js
,其中仅包含jQuery。显然,这很好,因为现在两个捆绑包中都不需要jQuery。
但是,由于bundle1.js
已加载到每个页面上,所以如果jQuery仅包含在bundle1
中,那就太好了。我该如何强制Webpack仅将jQuery放在bundle1.js
中而不是bundle2.js
中,而不将jQuery拆分成自己的公用包,而该包必须单独下载?
配置:
module.exports = {
mode: 'development',
entry: {
app: './js/app.js', // <-- loads on every page
editor: './js/editor.js' // <-- loads on certain pages
},
output: {
path: path.resolve('./js'),
filename: '[name].bundle.js'
},
optimization: {
splitChunks: {
chunks: 'all',
name: 'common'
}
}
}