Skip to content

Commit

Permalink
fix: allow chunk.modules mutation on js side (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Feb 19, 2025
1 parent 0f1475f commit 7e5a8b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1350,9 +1350,18 @@ function injectChunkMetadata(
chunkMetadataMap.set(key, {
importedAssets: new Set(),
importedCss: new Set(),
// NOTE: adding this as a workaround for now ideally we'd want to remove this workaround
// use shared `chunk.modules` object
// to allow mutation on js side plugins
__modules: chunk.modules,
})
}
chunk.viteMetadata = chunkMetadataMap.get(key)
Object.defineProperty(chunk, 'modules', {
get() {
return chunk.viteMetadata!.__modules
},
})
}

function injectEnvironmentInContext<Context extends MinimalPluginContext>(
Expand Down
1 change: 1 addition & 0 deletions packages/vite/types/metadata.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface ChunkMetadata {
importedAssets: Set<string>
importedCss: Set<string>
__modules: any
}

declare module 'rolldown' {
Expand Down

0 comments on commit 7e5a8b6

Please sign in to comment.