Skip to content

fix!: worker.plugins is a function - #14685

Merged
patak-cat merged 5 commits into
mainfrom
fix/worker-plugins-is-a-function
Oct 19, 2023
Merged

patak-cat merged 5 commits into
mainfrom
fix/worker-plugins-is-a-function

Conversation

@patak-cat

@patak-cat patak-cat commented Oct 18, 2023 •

Copy link
Copy Markdown
Member

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>
@bolt-new-by-stackblitz

Copy link
Copy Markdown

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

@patak-cat patak-cat added breaking change p3-significant High priority enhancement (priority) labels Oct 18, 2023
@patak-cat patak-cat added this to the 5.0 milestone Oct 18, 2023
@patak-cat

Copy link
Copy Markdown
Member Author

/ecosystem-ci run

@vite-ecosystem-ci

vite-ecosystem-ci Bot commented Oct 19, 2023 •

Copy link
Copy Markdown

📝 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

@bluwy bluwy left a comment

Copy link
Copy Markdown
Member

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.

Comment thread docs/config/worker-options.md Resolved
Comment thread docs/guide/migration.md Resolved
...workerPostPlugins,
]
workerConfig = await runConfigHook(workerConfig, workerUserPlugins, configEnv)
const resolvedWorkerOptions: ResolvedWorkerOptions = {

Copy link
Copy Markdown
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
Copy Markdown
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-cat 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-cat

Copy link
Copy Markdown
Member Author

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

@sapphi-red sapphi-red left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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.

Comment thread playground/worker/vite.config-iife.js Resolved
Comment thread docs/config/worker-options.md 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

Development

Successfully merging this pull request may close these issues.

Worker and build only error: Unexpected early exit. This happens when Promises returned by plugins cannot resolve

3 participants