-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Improve optimizeDeps.entries
to avoid server endpoints
#10143
Conversation
🦋 Changeset detectedLatest commit: f7224d6 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
entries: ['src/**/*'], | ||
// Scan all files within `srcDir` except for known server-code (e.g endpoints) | ||
entries: [ | ||
`${srcDirPattern}!(pages)/**/*`, // All files except for pages |
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.
I made some tests and it seems that srcDirPattern
will always have a trailing slash. The only case I'm not sure is on Windows.
// Scan all files within `srcDir` except for known server-code (e.g endpoints) | ||
entries: [ | ||
`${srcDirPattern}!(pages)/**/*`, // All files except for pages | ||
`${srcDirPattern}pages/**/!(*.js|*.ts)`, // All pages except for endpoints |
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.
Ehehe, unfortunately mjs
and cjs
should be included, even though it's a low chance that users use them. Still, we should
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.
Good catch! I'll add this too. I think perhaps for mjs and mts only. cjs and cts is unlikely to work in Astro and should have errors elsewhere if used.
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.
Looks good!
Changes
close #9859
Previously,
optimizeDeps.entries
set does not respect thesrcDir
option and globs into server endpoints, which we know should not contain browser code.optimizeDeps
should only be used on browser code.This PR fixes by respecting
srcDir
, and make sure server endpoints are not included in the glob. While this is not perfect in the bigger picture, and the ideal solution is to add a custom esbuild plugin to transform Astro files to allow the scanner to scan the appropriate browser files, this PR is an easier and quicker fix to the issue for now.Testing
It's a bit hard to test the overall behaviour, but I ran
DEBUG="vite:deps" pnpm dev
in the example projects to check that it logs the correct files globbed byoptimizeDeps.entries
.Docs
n/a. bug fix.