Skip to content

Speed up dev startup by pre-bundling external deps in optimizeDeps - #134

Merged
sneridagh merged 10 commits into
mainfrom
optimize_vite_deps
Jul 29, 2026
Merged

Speed up dev startup by pre-bundling external deps in optimizeDeps#134
sneridagh merged 10 commits into
mainfrom
optimize_vite_deps

Conversation

@arybakov05

@arybakov05 arybakov05 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

before:
image

after:
image


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

@arybakov05

arybakov05 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

@sneridagh @pnicolli Could this be useful? It does speed up the dev mode and it removes the three reloads when opening the page initially

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.js from being rewritten when its content is unchanged (avoids Vite restart loops).
  • Adds optimizeDeps.include entries in apps/aurora/vite.config.ts and introduces vite.extend.js files 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.

Comment thread apps/aurora/vite.config.ts
Comment thread apps/aurora/vite.config.ts Outdated
Comment thread apps/aurora/vite.config.ts
Comment thread docs/development/vite-optimize-deps.md
@pnicolli

Copy link
Copy Markdown
Collaborator

Could this be useful? It does speed up the dev mode and it removes the three reloads when opening the page initially

YES, definitely! Thanks!
I asked Copilot for a review as well since it should have a pretty good vite knowledge. I want to take a moment to review it myself anyway, in addition to Copilot's suggestions that I would recommend checking already.

Assigning Steve as well for docs review.

@sneridagh

Copy link
Copy Markdown
Member

@pnicolli @arybakov05 copilot's suggestions seem sound to me. Do you mind if I apply them immediately?

@arybakov05

Copy link
Copy Markdown
Contributor Author

@sneridagh Sure, go ahead

sneridagh and others added 2 commits June 14, 2026 12:13
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sneridagh

Copy link
Copy Markdown
Member

@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.

@arybakov05

Copy link
Copy Markdown
Contributor Author

The ssr.optimizeDeps deps are causing a small hiccup, the issue and proposed fix are described in the new PR #140

* 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
@sneridagh
sneridagh merged commit 5339f2f into main Jul 29, 2026
33 checks passed
@sneridagh
sneridagh deleted the optimize_vite_deps branch July 29, 2026 16:44
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.

4 participants