Skip to content

Commit

Permalink
feat: update manualChunks
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyuang committed Dec 30, 2021
1 parent 1383b50 commit b19bb7c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/server-utils/src/vite/config-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const manifestPlugin = (): Plugin => {
}
}

const vendorList = ['vue', 'vuex', 'vue-router', 'react', 'react-router', 'react-dom', 'create-context']
const vendorList = ['vue', 'vuex', 'vue-router', 'react', 'react-router', 'react-dom']

const rollupOutputOptions: OutputOptions = {
entryFileNames: 'Page.[hash].chunk.js',
Expand All @@ -93,10 +93,13 @@ const rollupOutputOptions: OutputOptions = {
return '[name].[hash].chunk.[ext]'
},
manualChunks: (id: string) => {
if (vendorList.includes(id)) {
if (id.includes('node_modules') && vendorList.includes(id)) {
// 优先级最高白名单里面的库必须被 vendor
return 'vendor'
}
if (id.includes('create-context')) {
return 'vendor'
}
if (originAsyncChunkMap?.[id]?.length >= 2) {
// 第二步处理公共模块。需要在第三步之前 否则 antd/es/style.js 这样的文件会被第三步包含
return cryptoAsyncChunkName(originAsyncChunkMap[id], asyncChunkMapJSON)
Expand Down

0 comments on commit b19bb7c

Please sign in to comment.