Skip to content

Commit

Permalink
fix(build): warn dynamic import module with a static import alongside
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed May 4, 2023
1 parent 9041e19 commit eb95a3c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/vite/src/node/plugins/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,24 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
compressedCount = 0
},

renderChunk() {
renderChunk(code, chunk) {
for (const id of chunk.moduleIds) {
const module = this.getModuleInfo(id)
if (!module) continue
if (module.importers.length && module.dynamicImporters.length) {
this.warn(
`\n(!) ${
module.id
} is dynamically imported by ${module.dynamicImporters
.map((m) => m)
.join(', ')} but also statically imported by ${module.importers
.map((m) => m)
.join(
', ',
)}, dynamic import will not move module into another chunk.\n`,
)
}
}
chunkCount++
if (shouldLogInfo) {
if (!tty) {
Expand Down
11 changes: 11 additions & 0 deletions playground/dynamic-import/__tests__/dynamic-import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,14 @@ test('should work with load ../ and contain itself directory', async () => {
true,
)
})

test.runIf(isBuild)(
'should rollup warn when static and dynamic import a module in same chunk',
async () => {
await untilUpdated(
() => serverLogs.join('\n'),
'dynamic import will not move module into another chunk',
true,
)
},
)

0 comments on commit eb95a3c

Please sign in to comment.