Navigation Menu

Skip to content

Commit

Permalink
fix(lib): enable inlineDynamicImports for umd and iife (#8126)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed May 11, 2022
1 parent 5ce7c74 commit 272a252
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion packages/vite/src/node/build.ts
Expand Up @@ -441,7 +441,10 @@ async function doBuild(
// #764 add `Symbol.toStringTag` when build es module into cjs chunk
// #1048 add `Symbol.toStringTag` for module default export
namespaceToStringTag: true,
inlineDynamicImports: ssr && typeof input === 'string',
inlineDynamicImports:
output.format === 'umd' ||
output.format === 'iife' ||
(ssr && typeof input === 'string'),
...output
}
}
Expand Down
2 changes: 1 addition & 1 deletion playground/lib/__tests__/lib.spec.ts
Expand Up @@ -40,7 +40,7 @@ describe.runIf(isBuild)('build', () => {
'hello vite'
)
const code = fs.readFileSync(
path.join(testDir(), 'dist/lib/dynamic-import-message.js'),
path.join(testDir(), 'dist/lib/dynamic-import-message.es.js'),
'utf-8'
)
expect(code).not.toMatch('__vitePreload')
Expand Down
4 changes: 2 additions & 2 deletions playground/lib/vite.dyimport.config.js
Expand Up @@ -8,9 +8,9 @@ module.exports = {
build: {
lib: {
entry: path.resolve(__dirname, 'src/main2.js'),
formats: ['es'],
formats: ['es', 'iife'],
name: 'message',
fileName: () => 'dynamic-import-message.js'
fileName: (format) => `dynamic-import-message.${format}.js`
},
outDir: 'dist/lib'
}
Expand Down

0 comments on commit 272a252

Please sign in to comment.