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!: worker.plugins is a function #14685

Merged
merged 5 commits into from
Oct 19, 2023
Merged

Conversation

patak-dev
Copy link
Member

@patak-dev patak-dev commented Oct 18, 2023

Fixes #13367

Description

This is a breaking change, changing the signature of worker.plugins to be a function instead of an array of plugins.

import myWorkerPlugin from 'my-worker-plugin';

export default {
   worker: {
      plugins: () => [myWorkerPlugin()]
   }
}

We move to a function to be able to get a fresh array of plugins every time we need to bundle a worker entry with rollup during build. This allows us to revert #11218 and have workers bundling in parallel.

The PR adds some of the tests from #14113 (has @jamsinclair as co-author).

mergeConfig is also modified so worker.plugins is merged as if it were an array.

worker.plugins() modifications in the config hook to config.worker will be ignored.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Co-authored-by: jamsinclair <jamsinclair@users.noreply.github.com>
@stackblitz
Copy link

stackblitz bot commented Oct 18, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@patak-dev patak-dev added breaking change p3-significant High priority enhancement (priority) labels Oct 18, 2023
@patak-dev patak-dev added this to the 5.0 milestone Oct 18, 2023
@patak-dev
Copy link
Member Author

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

vite-ecosystem-ci bot commented Oct 19, 2023

📝 Ran ecosystem CI: Open

suite result
analogjs ✅ success
astro ❌ failure
histoire ✅ success
ladle ✅ success
laravel ✅ success
marko ❌ failure
nuxt ✅ success
nx ❌ failure
previewjs ✅ success
qwik ❌ failure
rakkas ✅ success
sveltekit ❌ failure
unocss ✅ success
vike ❌ failure
vite-plugin-pwa ❌ failure
vite-plugin-react ✅ success
vite-plugin-react-pages ✅ success
vite-plugin-react-swc ✅ success
vite-plugin-svelte ✅ success
vite-plugin-vue ✅ success
vite-setup-catalogue ✅ success
vitepress ✅ success
vitest ❌ failure

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General logic looks good to me 👍 Got a couple suggestions below to improve a bit.

docs/config/worker-options.md Outdated Show resolved Hide resolved
docs/guide/migration.md Outdated Show resolved Hide resolved
...workerNormalPlugins,
...workerPostPlugins,
]
workerConfig = await runConfigHook(workerConfig, workerUserPlugins, configEnv)
const resolvedWorkerOptions: ResolvedWorkerOptions = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can move the workers resolve code as a function like resolveWorkerOptions? So it fits the pattern like the other more complex options. Might need a new file beside config.ts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that but it is using internal functions like filterPlugin, and I wanted to avoid changing unrelated parts on this PR. Maybe we could do that refactoring in another PR?

patak-dev and others added 2 commits October 19, 2023 09:30
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
@patak-dev
Copy link
Member Author

It seems the errors in ecosystem-ci aren't related to this PR, the same fails are right now in main.

Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good 👍 I have small suggestions and a question.

@@ -75,7 +52,7 @@ async function serialBundleWorkerEntry(
const bundle = await rollup({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's useful if there's a debug log here that shows the plugin names like we had here?
https://github.com/vitejs/vite/pull/14685/files#diff-11e17761d4ecfee8f8fde15c6d79b7bc0260176396a30dfd8e6f6bbaf5af4745R829

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to see how to do this only once because it will be too noisy if not having the logs everytime for projects that have a lot of workers. I'd say we merge it so it is part of the release and do this in a future PR.

playground/worker/vite.config-iife.js Outdated Show resolved Hide resolved
docs/config/worker-options.md Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change feat: web workers p3-significant High priority enhancement (priority)
Projects
None yet
3 participants