Skip to content

pass ?worker imports thru "worker" resolve condition #20230

@lukeed

Description

@lukeed

Description

There are custom worker configuration options, but it doesn't include the ability to customize its resolve or conditions config. Because of this, Vite's automatic handling of ?worker (+other) imports doesnt correctly load Worker-specific dependencies nor does it give me a way to do so.

Suggested solution

The request is to either
A) automatically include worker resolve condition when bundling a worker
probably breaking
B) expose more of the configuration to worker options so that I can quickly adjust w/o needing to rework the entire vite build to use custom envs


Thanks~!

Alternative

The alternative (afaict) is to

  1. Don't use `import Worker from './path?worker' at all
  2. Setup a custom environment that (re)defines all worker configuration, including the change in resolve conditions
  3. From client/main environment, instantiate my worker using hardcoded reference to the environments.worker.output path.

Additional context

When code is built within a worker, it should import from a given package's Worker-specific variant. Eg;

// package.json
{ 
  "name": "foobar",
  "exports": {
    ".": {
      "types": "...",
      "worker": "./worker.mjs",
      "browser": "./browser.mjs",
      "default": "./others.mjs"
    }
  }
}

Validations

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions