Skip to content

feat: add Vite Environment API support#903

Open
userquin wants to merge 11 commits intomainfrom
userqion/feat-add-env-api-support
Open

feat: add Vite Environment API support#903
userquin wants to merge 11 commits intomainfrom
userqion/feat-add-env-api-support

Conversation

@userquin
Copy link
Member

@userquin userquin commented Nov 13, 2025

Description

supersedes #786

Linked Issues

Additional Context


Tip

The author of this PR can publish a preview release by commenting /publish below.

@netlify
Copy link

netlify bot commented Nov 13, 2025

Deploy Preview for vite-plugin-pwa-legacy ready!

Name Link
🔨 Latest commit 8f1c4a0
🔍 Latest deploy log https://app.netlify.com/projects/vite-plugin-pwa-legacy/deploys/6976173790a9c20008079fac
😎 Deploy Preview https://deploy-preview-903--vite-plugin-pwa-legacy.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 13, 2025

npm i https://pkg.pr.new/vite-plugin-pwa@903

commit: 8f1c4a0

Copy link

Copilot AI left a comment

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 adds support for the Vite 6 Environment API while maintaining backward compatibility with Vite 5. The changes enable the plugin to work with Vite's new environment-based architecture for handling client and server environments separately.

Key changes:

  • Version detection mechanism to determine Vite 5 vs Vite 6 at runtime
  • Environment-aware configuration using the new configEnvironment hook
  • Updated WebSocket/HMR handling to use the new server.environments.client.hot API in Vite 6
  • SSR-aware build handling to skip PWA asset generation in SSR builds

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/context.ts Adds isVite6 Promise that detects Vite version by parsing the major version number from the imported Vite package
src/plugins/main.ts Adds configEnvironment hook for Vite 6 environment configuration and updates the config and load hooks to be environment-aware
src/plugins/pwa-assets.ts Updates handleHotUpdate and configureServer to use the new Environment API for module graph access and HMR communication in Vite 6
src/plugins/dev.ts Updates configureServer to use the new server.environments.client.hot API for WebSocket communication in Vite 6
src/plugins/build.ts Adds early return in generateBundle to skip PWA asset generation for SSR builds in Vite 6
src/options.ts Passes the isVite6 Promise to configureStaticAssets for SSR handling
src/assets.ts Adds early return in configureStaticAssets to skip static asset configuration for SSR builds in Vite 6
package.json Adds pnpm overrides to force Vite 6.0.1 for the main project and Vite 5.0.12 for VitePress
pnpm-lock.yaml Updates all dependency resolutions to reflect the Vite 6.0.1 upgrade and associated transitive dependency changes
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@userquin
Copy link
Member Author

userquin commented Nov 19, 2025

I need to review the plugins, looks like main resolve config hook being called 4 times per environment at nuxt pwa pr, last change/commit does nothing. I dont want to calculate assets hash 4 times, maybe we also need to export some utilities here and replace some other plugin at muxt integration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants