Speed up dev startup by pre-bundling external deps in optimizeDeps - #134
Conversation
|
@sneridagh @pnicolli Could this be useful? It does speed up the dev mode and it removes the three reloads when opening the page initially |
There was a problem hiding this comment.
Pull request overview
This PR improves Aurora’s Vite dev startup performance by (1) avoiding unnecessary regeneration of the registry-generated Vite loader (which can trigger restart loops) and (2) pre-declaring dependency pre-bundling via optimizeDeps.include for both the app and key workspace packages/add-ons. It also documents the intended workflow for declaring optimizeDeps entries in a pnpm monorepo.
Changes:
- Prevents
.plone/vite.loader.jsfrom being rewritten when its content is unchanged (avoids Vite restart loops). - Adds
optimizeDeps.includeentries inapps/aurora/vite.config.tsand introducesvite.extend.jsfiles for core add-ons to pre-bundle external deps. - Adds documentation describing how to declare
optimizeDeps(and where to do so depending on add-on vs non-add-on packages).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/registry/vite-plugin.js | Avoids rewriting generated Vite loader when content is unchanged to prevent restart loops. |
| packages/registry/news/+vite-extend-support.internal | Changelog entry for the loader write-change behavior. |
| packages/plate/vite.extend.js | Declares @plone/plate external deps for Vite pre-bundling. |
| packages/plate/news/+vite-optimize-deps.internal | Changelog entry for Plate optimizeDeps pre-bundling. |
| packages/layout/vite.extend.js | Declares @plone/layout external deps for Vite pre-bundling. |
| packages/layout/news/+vite-optimize-deps.internal | Changelog entry for Layout optimizeDeps pre-bundling. |
| packages/cmsui/vite.extend.js | Declares @plone/cmsui external deps for Vite pre-bundling. |
| packages/cmsui/news/+vite-optimize-deps.internal | Changelog entry for CMS UI optimizeDeps pre-bundling. |
| docs/development/vite-optimize-deps.md | New guide documenting how/where to declare optimizeDeps (add-ons vs app). |
| docs/development/index.md | Adds the new optimizeDeps doc page to the development docs index. |
| apps/aurora/vite.config.ts | Adds app-level optimizeDeps.include declarations for faster dev startup. |
| apps/aurora/news/+vite-optimize-deps.internal | Changelog entry for app-level optimizeDeps declarations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
YES, definitely! Thanks! Assigning Steve as well for docs review. |
|
@pnicolli @arybakov05 copilot's suggestions seem sound to me. Do you mind if I apply them immediately? |
|
@sneridagh Sure, go ahead |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@pnicolli @arybakov05 looks good!! I drop it to codex and it thought that we could do better, thus: #140 I am ok with merging this one, then the other when we have discussed it. |
|
The |
* Audit and document Vite optimizeDeps declarations * Address review feedback on optimizeDeps audit script - Declare typescript as an explicit devDependency of @plone/scripts instead of relying on it being hoisted from the repo root - Fix incorrect @openai attribution in the audit script news fragment - Dedupe the "OK" output line when multiple targets share a config file - Wire pnpm check:vite-optimize-deps into the Code Analysis CI workflow so drift between runtime imports and optimizeDeps declarations is caught automatically * Update pnpm-lock.yaml for typescript devDependency in @plone/scripts * Address arybakov05 review feedback on PR #140 - Exclude i18next-fs-backend and remix-i18next/server from the client optimizeDeps bundle: Vite's client-side scanner was still picking them up even though they were only declared under ssr.optimizeDeps.include - Scope check-vite-optimize-deps.js's declared-entries scan to actual `include` arrays instead of any string literal in the config file, so entries listed under `optimizeDeps.exclude` are no longer mistaken for satisfied declarations - Check named re-exports per-element for `isTypeOnly` instead of only at the export-statement level, so `export { type Foo } from 'pkg'` is no longer treated as a runtime dependency - Split expected specifiers into client vs. server-only (based on `*.server.*` filenames) and diff them against optimizeDeps.include and ssr.optimizeDeps.include separately, so drift in the SSR-only list is now actually caught - Document the client-exclude gotcha in vite-optimize-deps.md
before:

after:

📚 Documentation preview 📚: https://plone-aurora--134.org.readthedocs.build/