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

perf(nuxt): mark define functions as side-effect free at source #21434

Merged
merged 3 commits into from Jun 7, 2023

Conversation

antfu
Copy link
Member

@antfu antfu commented Jun 7, 2023

📚 Description

Rollup now supports marking a function as sied-effect free:

This PR marks the following functions as side-effect free

  • createClientOnly
  • defineNuxtComponent
  • defineNuxtLink
  • definePayloadPlugin
  • defineNuxtPlugin
  • useNuxtApp
  • useRuntimeConfig

As listed here:

pureAnnotationsPlugin.vite({
sourcemap: ctx.nuxt.options.sourcemap.client,
functions: ['defineComponent', 'defineAsyncComponent', 'defineNuxtLink', 'createClientOnly', 'defineNuxtPlugin', 'defineNuxtRouteMiddleware', 'defineNuxtComponent', 'useRuntimeConfig']
})

Side note: because we are esbuild to transpile, which does not preserve comments. We need to use /*! to keep the controlling comment, before esbuild supports __NO_SIDE_EFFECTS__ natively (evanw/esbuild#3149)

A PR was also sent to Vue core to mark defineComponent and defineAsyncComponent

Once this convention gets more widely adopted, we may be able to remove the pureAnnotationsPlugin later.

@nuxt-studio
Copy link

nuxt-studio bot commented Jun 7, 2023

Live Preview ready!

Name Edit Preview Latest Commit
Nuxt Docs Edit on Studio ↗︎ View Live Preview ac81938

@danielroe danielroe changed the title perf: mark define functions as side-effect free perf(nuxt): mark define functions as side-effect free at source Jun 7, 2023
@danielroe danielroe merged commit 6d59a02 into main Jun 7, 2023
22 checks passed
@danielroe danielroe deleted the perf/no-side-effects branch June 7, 2023 10:11
@github-actions github-actions bot mentioned this pull request Jun 7, 2023
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.

None yet

2 participants