-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
refactor(nuxt,vite): use environment-api compatible plugins #33403
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
Conversation
|
|
WalkthroughThe changes shift several integrations to environment-scoped Vite plugins. IslandsTransformPlugin is registered with prepend: true. Nitro now injects a client-only Vite plugin to alias vue to the runtime-compiler build. ResolveDeepImportsPlugin computes and caches per-environment resolve conditions and uses them during resolveId. ResolvedExternalsPlugin moves to applyToEnvironment, conditionally building externals for production SSR using Nitro data. Vite server config gains environments.ssr.resolve.conditions sourced from Nitro exportConditions. Nuxt core plugin registrations are de-scoped and reordered with prepend where applicable. Minor formatting and import consolidations are applied, and the test fixture updates vite:extend usage and plugin enforce: 'pre'. Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
packages/nuxt/src/components/module.ts(1 hunks)packages/nuxt/src/core/nitro.ts(2 hunks)packages/nuxt/src/core/nuxt.ts(2 hunks)packages/nuxt/src/core/plugins/resolve-deep-imports.ts(3 hunks)packages/nuxt/src/core/plugins/resolved-externals.ts(1 hunks)packages/nuxt/src/pages/plugins/page-meta.ts(1 hunks)packages/vite/src/server.ts(1 hunks)test/fixtures/basic/nuxt.config.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Follow standard TypeScript conventions and best practices
Files:
packages/nuxt/src/components/module.tspackages/vite/src/server.tspackages/nuxt/src/core/nuxt.tspackages/nuxt/src/pages/plugins/page-meta.tspackages/nuxt/src/core/plugins/resolved-externals.tspackages/nuxt/src/core/plugins/resolve-deep-imports.tspackages/nuxt/src/core/nitro.tstest/fixtures/basic/nuxt.config.ts
🧠 Learnings (2)
📚 Learning: 2024-11-05T15:22:54.759Z
Learnt from: GalacticHypernova
PR: nuxt/nuxt#26468
File: packages/nuxt/src/components/plugins/loader.ts:24-24
Timestamp: 2024-11-05T15:22:54.759Z
Learning: In `packages/nuxt/src/components/plugins/loader.ts`, the references to `resolve` and `distDir` are legacy code from before Nuxt used the new unplugin VFS and will be removed.
Applied to files:
packages/nuxt/src/core/nuxt.ts
📚 Learning: 2024-12-12T12:36:34.871Z
Learnt from: huang-julien
PR: nuxt/nuxt#29366
File: packages/nuxt/src/app/components/nuxt-root.vue:16-19
Timestamp: 2024-12-12T12:36:34.871Z
Learning: In `packages/nuxt/src/app/components/nuxt-root.vue`, when optimizing bundle size by conditionally importing components based on route metadata, prefer using inline conditional imports like:
```js
const IsolatedPage = route?.meta?.isolate ? defineAsyncComponent(() => import('#build/isolated-page.mjs')) : null
```
instead of wrapping the import in a computed property or importing the component unconditionally.
Applied to files:
packages/nuxt/src/pages/plugins/page-meta.ts
🧬 Code graph analysis (5)
packages/nuxt/src/components/module.ts (2)
packages/kit/src/build.ts (1)
addBuildPlugin(153-165)packages/nuxt/src/components/plugins/islands-transform.ts (1)
IslandsTransformPlugin(32-143)
packages/nuxt/src/core/nuxt.ts (3)
packages/kit/src/build.ts (1)
addVitePlugin(137-145)packages/nuxt/src/core/plugins/resolve-deep-imports.ts (1)
ResolveDeepImportsPlugin(13-79)packages/nuxt/src/core/plugins/resolved-externals.ts (1)
ResolveExternalsPlugin(8-57)
packages/nuxt/src/core/plugins/resolved-externals.ts (1)
packages/kit/src/nitro.ts (1)
useNitro(78-84)
packages/nuxt/src/core/plugins/resolve-deep-imports.ts (2)
packages/kit/src/index.ts (1)
directoryToURL(43-43)packages/kit/src/internal/esm.ts (1)
directoryToURL(13-15)
packages/nuxt/src/core/nitro.ts (1)
packages/kit/src/build.ts (1)
addVitePlugin(137-145)
🔇 Additional comments (3)
packages/nuxt/src/core/plugins/resolved-externals.ts (3)
2-2: Import change looks correct.The addition of
useNitroto the imports is necessary for accessing the Nitro instance.
15-35: Environment-aware externals logic is well-implemented.The
applyToEnvironmentimplementation correctly:
- Returns
falsefor dev mode or non-SSR environments, avoiding unnecessary work- Defers fetching Nitro runtime dependencies until needed
- Constructs the external set with appropriate dependencies
- Uses
nitro.options.inlineDynamicImportsfor conditional Vue inclusionThe logic aligns with the PR objective of making plugins environment-aware.
8-10: Verify Nitro readiness in ResolveExternalsPlugin
Ensure theuseNitro()call inResolveExternalsPluginruns only after thenitro:inithook (addVitePlugin callbacks should execute post-initialisation); if this isn’t guaranteed, deferuseNitro()into a plugin hook (e.g.configorbuildStart).
| const resolvedConditions = new Set([nuxt.options.dev ? 'development' : 'production', ...environment.config.resolve.conditions]) | ||
| if (resolvedConditions.has('browser')) { | ||
| resolvedConditions.add('web') | ||
| resolvedConditions.add('import') | ||
| resolvedConditions.add('module') | ||
| resolvedConditions.add('default') | ||
| } | ||
| if (environment.config.mode === 'test') { | ||
| resolvedConditions.add('import') | ||
| resolvedConditions.add('require') | ||
| } | ||
| return [...resolvedConditions] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard against missing resolve.conditions
environment.config.resolve.conditions can be undefined (e.g. when Nitro hasn’t populated export conditions yet), so spreading it throws TypeError: object is not iterable. Please default it to an empty array before constructing the Set, e.g. ...(environment.config.resolve.conditions ?? []), and reuse the same guard when caching in environmentConditions.
Also applies to: 62-68
🤖 Prompt for AI Agents
In packages/nuxt/src/core/plugins/resolve-deep-imports.ts around lines 19-31
(and similarly lines 62-68), spreading environment.config.resolve.conditions can
throw when it's undefined; change all occurrences to spread a safe default such
as ...(environment.config.resolve.conditions ?? []) when constructing
resolvedConditions (and when populating environmentConditions cache) so the code
uses an empty array if conditions is missing.
@nuxt/kit
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
CodSpeed Performance ReportMerging #33403 will not alter performanceComparing Summary
|
🔗 Linked issue
📚 Description
this ports some changes from #33262 to make the diff more straightforward