Skip to content

fix(dev): apply define constants to worker files in dev mode - #23236

Open
waterWang wants to merge 1 commit into
vitejs:mainfrom
waterWang:fix/worker-define-dev
Open

fix(dev): apply define constants to worker files in dev mode#23236
waterWang wants to merge 1 commit into
vitejs:mainfrom
waterWang:fix/worker-define-dev

Conversation

@waterWang

Copy link
Copy Markdown

Description

In dev mode, the definePlugin skips transforms for all files when
consumer is client, relying on the vite client's global injection
for the main thread. However, Web Workers run in a separate global
scope and cannot access the defines injected into the main thread.

This fix detects worker file requests (identified by the worker_file
query parameter) and applies the define transform even in dev mode,
ensuring that user-defined constants like
define: { __SOME_CONSTANT__: 128 } are properly replaced in
worker files.

Additional context

Fixes #23234

What is the purpose of this pull request?

  • Bug fix
  • New feature
  • Documentation update
  • Other

In dev mode, the define plugin skips transforms for all files when
consumer is 'client', relying on the vite client's global injection
for the main thread. However, Web Workers run in a separate global
scope and cannot access the defines injected into the main thread.

This fix detects worker file requests (identified by the
'worker_file' query parameter) and applies the define transform
even in dev mode, ensuring that user-defined constants like
define: { __SOME_CONSTANT__: 128 } are properly replaced in
worker files.

Fixes vitejs#23234
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

config: define constants are not loaded on Workers

1 participant