Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose vite's default manualChunks function #5585

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/playground/vue/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import path from 'path'
import { defineConfig } from 'vite'
import vuePlugin from '@vitejs/plugin-vue'
import { vueI18nPlugin } from './CustomBlockPlugin'
import { createMoveToVendorChunkFn } from 'vite'
const viteChunks = createMoveToVendorChunkFn()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache is not going to be cleaned up correctly during build watch if it is defined in this way. I think we are having an issue in Vite here, no? This cache should be cleaned in buildStart. Maybe we should move it out of the function, and into the plugin control.
Maybe we could end up exposing a single function instead of factory afterwards?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-analyzed the building logic, the problem does exist, I will push a new commit for review : )

Copy link
Member Author

@ygj6 ygj6 Nov 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please focus on checking whether it needs to be cleared here?

b9f1826#diff-aa53520bfd53e6c24220c44494457cc66370fd2bee513c15f9be7eb537a363e7R564-R565

Will the parallelCallCounts introduced by 4a955bc actually be greater than 1? I tested several scenarios that I expected and found nothing. If it is greater than, maybe parallel build will affect the shared cache?

Open a new thread below for tracking.


export default defineConfig({
resolve: {
Expand All @@ -17,7 +19,18 @@ export default defineConfig({
],
build: {
// to make tests faster
minify: false
minify: false,
rollupOptions: {
output: {
// partial override of vite's manualChunks
manualChunks: (id, api) => {
if (id.includes('node_modules') && id.includes('vue')) {
return 'vue-chunk'
}
return viteChunks(id, api)
}
}
}
},
css: {
modules: {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ async function doBuild(
!libOptions &&
output?.format !== 'umd' &&
output?.format !== 'iife'
? createMoveToVendorChunkFn(config)
? createMoveToVendorChunkFn()
: undefined,
...output
}
Expand Down Expand Up @@ -605,7 +605,7 @@ function getPkgName(root: string) {
return name?.startsWith('@') ? name.split('/')[1] : name
}

function createMoveToVendorChunkFn(config: ResolvedConfig): GetManualChunk {
export function createMoveToVendorChunkFn(): GetManualChunk {
const cache = new Map<string, boolean>()
return (id, { getModuleInfo }) => {
if (
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './config'
export { createServer, searchForWorkspaceRoot } from './server'
export { preview } from './preview'
export { build } from './build'
export { build, createMoveToVendorChunkFn } from './build'
export { optimizeDeps } from './optimizer'
export { send } from './server/send'
export { createLogger, printHttpServerUrls } from './logger'
Expand Down