Javascript Webpack-4如何使用多个条目和SSR进行独立和有条件的分割块
我想从某个包中生成多个块,并使用服务器有条件地呈现的块。将或不确定脚本放入 html由另一个应用程序控制,这不是问题。我尝试使用可加载组件,但不适用于我,因为他生成了糟糕的树依赖关系Javascript Webpack-4如何使用多个条目和SSR进行独立和有条件的分割块,javascript,webpack,vendor,webpack-splitchunks,splitchunksplugin,Javascript,Webpack,Vendor,Webpack Splitchunks,Splitchunksplugin,我想从某个包中生成多个块,并使用服务器有条件地呈现的块。将或不确定脚本放入 html由另一个应用程序控制,这不是问题。我尝试使用可加载组件,但不适用于我,因为他生成了糟糕的树依赖关系 export const entry = { testAB: testABPath, clients: clientsPath, styles: stylesPath, amp: ampPath, } 然后,我有: export const optimization = { splitChu
export const entry = {
testAB: testABPath,
clients: clientsPath,
styles: stylesPath,
amp: ampPath,
}
然后,我有:
export const optimization = {
splitChunks: {
chunks: 'async',
cacheGroups: {
vendor: {
test(mod) { return checkTest(/[\\/]node_modules[\\/]/, mod)},
name: 'vendor',
reuseExistingChunk: true,
filename: '[name].bundle.js',
priority: -10,
chunks: 'all'
},
headerA: {
test: new Regex('/app/src/modules/header/headerA'),
name: 'header-module-A',
reuseExistingChunk: true,
filename: '[name].bundle.js',
priority: -10,
chunks: 'all'
},
headerB: {
test: new Regex('/app/src/modules/header/headerB'),
name: 'header-module-B',
reuseExistingChunk: true,
filename: '[name].bundle.js',
priority: -10,
chunks: 'all'
}
}
}
}
这将生成一个clients.js,不包含Header模块代码,Header-module-a和Header-module-B文件,很酷
情景1
我在页面中调用clients.js、header-module-A和header-module-B。一切都很好
场景2
我在某个页面中调用clients.js,header-module-A,但没有header-module-B。clients.js文件不起作用,因为他的头文件-module-b有一个依赖项(该文件使用checkDeferredModules函数检查所有模块)
此时,我发现这个解决方案带有runtimeChunk:“single”选项,这些选项将生成一个新的运行时文件。我在这一点上的配置如下:
export const optimization = {
runtimeChunk: 'single',
splitChunks: {
chunks: 'async',
cacheGroups: {
vendor: {
test(mod) { return checkTest(/[\\/]node_modules[\\/]/, mod)},
name: 'vendor',
reuseExistingChunk: true,
filename: '[name].bundle.js',
priority: -10,
chunks: 'all'
},
...getOtherChunks,
}
}
}
我已经将runtime.js文件放在了页眉,其余的脚本放在了页脚,但不起作用
新场景1
我在页面中调用clients.js、header-module-A和header-module-B。标题不起作用
新场景2
我在某个页面中调用clients.js,header-module-A,但没有header-module-B。标题不起作用
我做错了什么