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

feat: worker support query url #7914

Merged
merged 11 commits into from
May 21, 2022
Merged

Conversation

poyoho
Copy link
Member

@poyoho poyoho commented Apr 26, 2022

Description

fix: #7569

Additional context

feat support below syntax to import worker url.

import workerUrl from '../simple-worker?worker&url'

function text(el, text) {
  document.querySelector(el).textContent = text
}

const worker = new Worker(workerUrl, { type: 'classic' })

worker.addEventListener('message', (ev) => {
  text('.simple-worker-url', JSON.stringify(ev.data))
})

about new URL

new URL('./hello.js?worker', import.meta.url)

I think new URL is better not to add too much non-conforming syntax, so I do not support it now. And if the href is not added to break the workerImportMetaUrl match, it may make another issues

For example:

new Worker(new URL('./hello.js?worker', import.meta.url))

And doing a little refactor, I think worker related logic should be in worker.ts.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

packages/vite/src/node/plugins/worker.ts Outdated Show resolved Hide resolved
packages/vite/src/node/plugins/worker.ts Outdated Show resolved Hide resolved
packages/vite/src/node/plugins/worker.ts Outdated Show resolved Hide resolved
bluwy
bluwy previously approved these changes Apr 27, 2022
@sapphi-red
Copy link
Member

It seems this PR supersedes #5845.

@poyoho
Copy link
Member Author

poyoho commented Apr 29, 2022

oh, If the Author goto rebase and complementing his missing parts of this I will close this.

@bluwy
Copy link
Member

bluwy commented Apr 29, 2022

I'd still be in favour of this PR though as it has more tests and refactors 🙂

@patak-dev patak-dev added this to the 3.0 milestone May 2, 2022
@patak-dev patak-dev added the p2-nice-to-have Not breaking anything but nice to have (priority) label May 2, 2022
bluwy
bluwy previously approved these changes May 18, 2022
@patak-dev
Copy link
Member

For reference, we talked with the team about the PR and we are good to merge it. We tried to find a way to avoid introducing new URL queries but this feature justifies the addition, and there doesn't seem to be any other way until the standard evolves to support modifiers. Let's merge the PR once it is rebased.

@poyoho
Copy link
Member Author

poyoho commented May 21, 2022

For reference, we talked with the team about the PR and we are good to merge it. We tried to find a way to avoid introducing new URL queries but this feature justifies the addition, and there doesn't seem to be any other way until the standard evolves to support modifiers. Let's merge the PR once it is rebased.

May be we can clean all the url query in vite@4 😁

@patak-dev patak-dev merged commit 95297dd into vitejs:main May 21, 2022
@poyoho poyoho deleted the feat/worker-query-url branch May 21, 2022 07:59
@sapphi-red sapphi-red mentioned this pull request Sep 30, 2022
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: web workers p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Worker does not go through some plugins in vite build, but does in development
4 participants