mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 14:48:41 +00:00
fix(build): silence warn dynamic import module when inlineDynamicImports true (#13970)
This commit is contained in:
parent
2c73d10ed2
commit
7a77aaf28b
@ -119,7 +119,8 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
|
||||
compressedCount = 0
|
||||
},
|
||||
|
||||
renderChunk(code, chunk) {
|
||||
renderChunk(code, chunk, options) {
|
||||
if (!options.inlineDynamicImports) {
|
||||
for (const id of chunk.moduleIds) {
|
||||
const module = this.getModuleInfo(id)
|
||||
if (!module) continue
|
||||
@ -130,7 +131,8 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
|
||||
// the same chunk. The intersecting dynamic importers' dynamic import is not
|
||||
// expected to work. Note we're only detecting the direct ineffective
|
||||
// dynamic import here.
|
||||
const detectedIneffectiveDynamicImport = module.dynamicImporters.some(
|
||||
const detectedIneffectiveDynamicImport =
|
||||
module.dynamicImporters.some(
|
||||
(id) => !isInNodeModules(id) && chunk.moduleIds.includes(id),
|
||||
)
|
||||
if (detectedIneffectiveDynamicImport) {
|
||||
@ -146,6 +148,7 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
chunkCount++
|
||||
if (shouldLogInfo) {
|
||||
|
@ -0,0 +1,12 @@
|
||||
import { expect, test } from 'vitest'
|
||||
import { isBuild, serverLogs } from '~utils'
|
||||
|
||||
test.runIf(isBuild)(
|
||||
'dont warn when inlineDynamicImports is set to true',
|
||||
async () => {
|
||||
const log = serverLogs.join('\n')
|
||||
expect(log).not.toContain(
|
||||
'dynamic import will not move module into another chunk',
|
||||
)
|
||||
},
|
||||
)
|
1
playground/dynamic-import-inline/index.html
Normal file
1
playground/dynamic-import-inline/index.html
Normal file
@ -0,0 +1 @@
|
||||
<script type="module" src="./src/index.js"></script>
|
12
playground/dynamic-import-inline/package.json
Normal file
12
playground/dynamic-import-inline/package.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "@vitejs/test-dynamic-import-inline",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"debug": "node --inspect-brk ../../packages/vite/bin/vite",
|
||||
"preview": "vite preview"
|
||||
}
|
||||
}
|
3
playground/dynamic-import-inline/src/foo.js
Normal file
3
playground/dynamic-import-inline/src/foo.js
Normal file
@ -0,0 +1,3 @@
|
||||
export default function foo() {
|
||||
return 'foo'
|
||||
}
|
9
playground/dynamic-import-inline/src/index.js
Normal file
9
playground/dynamic-import-inline/src/index.js
Normal file
@ -0,0 +1,9 @@
|
||||
import foo from './foo'
|
||||
|
||||
const asyncImport = async () => {
|
||||
const { foo } = await import('./foo.js')
|
||||
foo()
|
||||
}
|
||||
|
||||
foo()
|
||||
asyncImport()
|
18
playground/dynamic-import-inline/vite.config.js
Normal file
18
playground/dynamic-import-inline/vite.config.js
Normal file
@ -0,0 +1,18 @@
|
||||
import path from 'node:path'
|
||||
import { defineConfig } from 'vite'
|
||||
|
||||
export default defineConfig({
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, 'alias'),
|
||||
},
|
||||
},
|
||||
build: {
|
||||
sourcemap: true,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
inlineDynamicImports: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
Loading…
Reference in New Issue
Block a user