Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lib): enable inlineDynamicImports for umd and iife #8126

Merged
merged 1 commit into from May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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