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

Custom environment with webCompatible: true implying inlineDynamicImports: true might be surprising #18233

Open
7 tasks done
hi-ogawa opened this issue Sep 30, 2024 · 0 comments

Comments

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Sep 30, 2024

Describe the bug

I know it's been discussed that webCompatible needs to be a more fine-grained option, but this one confused me a bit, so I'm reporting it here so not to forget.

It looks like old ssr.target: "webworker" now corresponds to consumer: "server" + webCompatible: true, so inlineDynamicImports: true kicks in even for esm build:

inlineDynamicImports:
output.format === 'umd' ||
output.format === 'iife' ||
(environment.config.consumer === 'server' &&
environment.config.webCompatible &&
(typeof input === 'string' || Object.keys(input).length === 1)),

(Context: I noticed this when I was using emitFile({ type: "chunk" }) in my web worker example https://github.com/hi-ogawa/vite-environment-examples/tree/main/examples/web-worker but emitted files are not splitas I expected.)

Reproduction

https://stackblitz.com/github/hi-ogawa/reproductions/tree/main/vite-environment-inlineDynamicImport?file=vite.config.ts

Steps to reproduce

vite v6.0.0-beta.1 building SSR bundle for production...
✓ 2 modules transformed.
dist/index.js  0.35 kB
✓ built in 74ms
  • after explicitly disabling inlineDynamicImports: false, then run pnpm build
vite v6.0.0-beta.1 building SSR bundle for production...
✓ 2 modules transformed.
dist/assets/dep-dynamic-Cvylvt0M.js  0.07 kB
dist/index.js                        0.13 kB
✓ built in 84ms

System Info

(stackblitz)


  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: 6.0.0-beta.1 => 6.0.0-beta.1

Used Package Manager

npm

Logs

No response

Validations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant