Skip to content

Commit 272a252

Browse files
authored
fix(lib): enable inlineDynamicImports for umd and iife (#8126)
1 parent 5ce7c74 commit 272a252

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

packages/vite/src/node/build.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,10 @@ async function doBuild(
441441
// #764 add `Symbol.toStringTag` when build es module into cjs chunk
442442
// #1048 add `Symbol.toStringTag` for module default export
443443
namespaceToStringTag: true,
444-
inlineDynamicImports: ssr && typeof input === 'string',
444+
inlineDynamicImports:
445+
output.format === 'umd' ||
446+
output.format === 'iife' ||
447+
(ssr && typeof input === 'string'),
445448
...output
446449
}
447450
}

playground/lib/__tests__/lib.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe.runIf(isBuild)('build', () => {
4040
'hello vite'
4141
)
4242
const code = fs.readFileSync(
43-
path.join(testDir(), 'dist/lib/dynamic-import-message.js'),
43+
path.join(testDir(), 'dist/lib/dynamic-import-message.es.js'),
4444
'utf-8'
4545
)
4646
expect(code).not.toMatch('__vitePreload')

playground/lib/vite.dyimport.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module.exports = {
88
build: {
99
lib: {
1010
entry: path.resolve(__dirname, 'src/main2.js'),
11-
formats: ['es'],
11+
formats: ['es', 'iife'],
1212
name: 'message',
13-
fileName: () => 'dynamic-import-message.js'
13+
fileName: (format) => `dynamic-import-message.${format}.js`
1414
},
1515
outDir: 'dist/lib'
1616
}

0 commit comments

Comments
 (0)