Skip to content

Commit 5e65161

Browse files
hi-ogawasapphi-red
authored andcommitted
fix: allow chunk.modules mutation on js side (#82)
1 parent 6a036e4 commit 5e65161

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

packages/vite/src/node/build.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,9 +1350,18 @@ function injectChunkMetadata(
13501350
chunkMetadataMap.set(key, {
13511351
importedAssets: new Set(),
13521352
importedCss: new Set(),
1353+
// NOTE: adding this as a workaround for now ideally we'd want to remove this workaround
1354+
// use shared `chunk.modules` object
1355+
// to allow mutation on js side plugins
1356+
__modules: chunk.modules,
13531357
})
13541358
}
13551359
chunk.viteMetadata = chunkMetadataMap.get(key)
1360+
Object.defineProperty(chunk, 'modules', {
1361+
get() {
1362+
return chunk.viteMetadata!.__modules
1363+
},
1364+
})
13561365
}
13571366

13581367
function injectEnvironmentInContext<Context extends MinimalPluginContext>(

packages/vite/types/metadata.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export interface ChunkMetadata {
22
importedAssets: Set<string>
33
importedCss: Set<string>
4+
__modules: any
45
}
56

67
declare module 'rolldown' {

0 commit comments

Comments
 (0)