mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Improve optimizeDeps.entries
to avoid server endpoints (#10143)
This commit is contained in:
parent
2c2519204a
commit
7c5fcd2fa8
2 changed files with 15 additions and 1 deletions
5
.changeset/funny-bananas-switch.md
Normal file
5
.changeset/funny-bananas-switch.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Improves the default `optimizeDeps.entries` Vite config to avoid globbing server endpoints, and respect the `srcDir` option
|
|
@ -1,5 +1,6 @@
|
|||
import nodeFs from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import glob from 'fast-glob';
|
||||
import * as vite from 'vite';
|
||||
import { crawlFrameworkPkgs } from 'vitefu';
|
||||
import type { AstroSettings } from '../@types/astro.js';
|
||||
|
@ -103,6 +104,8 @@ export async function createVite(
|
|||
},
|
||||
});
|
||||
|
||||
const srcDirPattern = glob.convertPathToPattern(fileURLToPath(settings.config.srcDir));
|
||||
|
||||
// Start with the Vite configuration that Astro core needs
|
||||
const commonConfig: vite.InlineConfig = {
|
||||
// Tell Vite not to combine config from vite.config.js with our provided inline config
|
||||
|
@ -112,7 +115,13 @@ export async function createVite(
|
|||
customLogger: createViteLogger(logger, settings.config.vite.logLevel),
|
||||
appType: 'custom',
|
||||
optimizeDeps: {
|
||||
entries: ['src/**/*'],
|
||||
// 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)
|
||||
],
|
||||
exclude: ['astro', 'node-fetch'],
|
||||
},
|
||||
plugins: [
|
||||
|
|
Loading…
Reference in a new issue