Skip to content

Commit

Permalink
Only add framework component formats to Vite’s optimizeDeps (#11472)
Browse files Browse the repository at this point in the history
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
  • Loading branch information
delucis and bluwy authored Jul 17, 2024
1 parent 3070691 commit cb4e6d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-spies-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Avoids targeting all files in the `src/` directory for eager optimization by Vite. After this change, only JSX, Vue, Svelte, and Astro components get scanned for early optimization.
9 changes: 2 additions & 7 deletions packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,8 @@ export async function createVite(
customLogger: createViteLogger(logger, settings.config.vite.logLevel),
appType: 'custom',
optimizeDeps: {
// Scan all files within `srcDir` except for known server-code (e.g endpoints)
entries: [
`${srcDirPattern}!(pages)/**/*`, // All files except for pages
`${srcDirPattern}pages/**/!(*.js|*.mjs|*.ts|*.mts)`, // All pages except for endpoints
`${srcDirPattern}pages/**/_*.{js,mjs,ts,mts}`, // Remaining JS/TS files prefixed with `_` (not endpoints)
`${srcDirPattern}pages/**/_*/**/*.{js,mjs,ts,mts}`, // Remaining JS/TS files within directories prefixed with `_` (not endpoints)
],
// Scan for component code within `srcDir`
entries: [`${srcDirPattern}**/*.{jsx,tsx,vue,svelte,html,astro}`],
exclude: ['astro', 'node-fetch'],
},
plugins: [
Expand Down

0 comments on commit cb4e6d0

Please sign in to comment.