Skip to content
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

Support Vite 5 #9122

Merged
merged 2 commits into from
Nov 17, 2023
Merged

Support Vite 5 #9122

merged 2 commits into from
Nov 17, 2023

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Nov 17, 2023

Changes

  • Bump to Vite 5
  • Bump to Rollup 4
  • Update Vite plugins to support Vite 5
  • Update vite-plugin-astro-preview to handle certain URLs that Vite 5 doesn't handle anymore

PS: I'm not sure why pnpm updated te lockfile to be larger. It should be fixed when we bump all the deps to latest later.

Testing

Tested manually. Ran all tests locally which passed.

Docs

I think we only need to mention this in the migration guide.

Copy link

changeset-bot bot commented Nov 17, 2023

🦋 Changeset detected

Latest commit: 734a1f7

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

@github-actions github-actions bot added pkg: svelte Related to Svelte (scope) pkg: vue Related to Vue (scope) pkg: react Related to React (scope) pkg: integration Related to any renderer integration (scope) pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review labels Nov 17, 2023
Comment on lines +76 to 77
// @ts-expect-error there's a bug with the types where the first arg should be optional
resolvedOptions.preprocess = vitePreprocess();
Copy link
Member Author

Choose a reason for hiding this comment

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

I've sent a PR upstream to fix it. If it's released, I'll update this part before merging.

Comment on lines +60 to 67
// Vite doesn't handle /foo/ if /foo.html exists, we handle it anyways
if (pathname.endsWith('/')) {
const pathnameWithoutSlash = pathname.slice(0, -1);
const htmlPath = fileURLToPath(outDir + pathnameWithoutSlash + '.html');
if (fs.existsSync(htmlPath)) {
req.url = pathnameWithoutSlash + '.html';
return next();
}
Copy link
Member Author

Choose a reason for hiding this comment

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

The comment above should clarify what this does. But to further explain why we're assigning to req.url, this is for a later Vite middleware to load the files. We only need to update the req.url so that middleware can detect a HTML file.

@@ -72,8 +72,6 @@ export default async function createStaticPreviewServer(
host: getResolvedHostForHttpServer(settings.config.server.host),
port: settings.config.server.port,
closed,
// In Vite 5, `httpServer` may be a `Http2SecureServer`, but we know we are only starting a HTTP server
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
server: previewServer.httpServer as http.Server,
Copy link
Member

@Princesseuh Princesseuh Nov 17, 2023

Choose a reason for hiding this comment

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

Is there a world where we'd want to support https for the preview server? Unrelated to this, just wondering.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could! At the moment we have control over the config passed to Vite's preview() so we know this will always be a http server. If we open up to the config from astro.config.mjs in the future, they can create https servers.

@@ -1,4 +1,4 @@
import { defineConfig } from 'rollup'
Copy link
Member

Choose a reason for hiding this comment

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

lol

Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @bluwy 🚀

@bluwy bluwy merged commit 1c48ed2 into next Nov 17, 2023
13 checks passed
@bluwy bluwy deleted the support-vite-5 branch November 17, 2023 14:02
@astrobot-houston astrobot-houston mentioned this pull request Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope) pkg: react Related to React (scope) pkg: svelte Related to Svelte (scope) pkg: vue Related to Vue (scope) pr: docs A PR that includes documentation for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants