更新日志
请参阅相应的安装部分:
- vite-plugin-pwa
- @vite-pwa/sveltekit
- @vite-pwa/vitepress
- @vite-pwa/astro
- @vite-pwa/nuxt
- @vite-pwa/assets-generator
- @vite-pwa/create-pwa
@vite-pwa/create-pwa from v0.6.0
From version v0.6.0, all the templates to use Vite 6, including also the latest frameworks changes.
Use version v0.5.0 for Vite 5 and previous versions of the frameworks.
SvelteKit Single-page App Support from v0.6.7
From v0.6.7, @vite-pwa/sveltekit adds support for single-page apps, including also:
- add
static-adapterfallback in the service worker precache manifest in SPA mode - update
globPatternsto include__data.jsonfiles when usingstatic-adapterwithloadfunctions
Check the SvelteKit documentation for further details.
Vite 6 support from v0.21.1
From v0.21.1, vite-plugin-pwa adds support for Vite 6:
- should also work with Vite 3, 4 and 5.
- still not using the Vite 6 Environment API.
If you want to use vite-plugin-pwa with Vite 6 Environment API, check this PR: feat!: add Vite 6 Environment API support: install the vite-plugin-pwa version from pkg-pr-new using the last commit (click on the commit link in the pkg-pr-new comment ):
pnpm add -D https://pkg.pr.new/vite-plugin-pwa@88b2e45yarn add -D https://pkg.pr.new/vite-plugin-pwa@88b2e45npm i -D https://pkg.pr.new/vite-plugin-pwa@88b2e45INFO
vite-plugin-pwa should still work with Vite 3, 4 and 5.
Workbox 7.3.0 from v0.21.0
From v0.21.0, vite-plugin-pwa updates workbox to 7.3.0.
Workbox 7.3.0 from v0.21.0
From v0.21.0, vite-plugin-pwa updates workbox to 7.3.0.
Service worker 构建 从 v0.20.2
从 v0.20.2 开始,如果在构建 service worker 时出现 maximumFileSizeToCacheInBytes 警告,插件将抛出错误。
Workbox 7.1.0 从 v0.20.0
从 v0.20.0 、 vite-plugin-pwa 更新 workbox 为 7.1.0。
Workbox 已弃用workbox-google-analytics,它不再兼容较新的 Google Analytics v4。
更新 Vite 构建 从 v0.19.6
这些新功能只能在集成时使用
From v0.19.6, vite-plugin-pwa adds envOptions option to injectManifest to allow customizing the environment options for the service worker build output:
envDir: you can change theenvDir, the plugin will use the Vite's envDir option if not configuredenvPrefix: you can change theenvPrefix, the plugin will use the Vite's envDir option if not configured
vite-plugin-pwa also includes the new configureCustomSWViteBuild integration option to allow you to change the Vite's build options for the custom service worker build, check the PWAIntegration type definition for more details.
PWA Assets 从 v0.19.0 实验性的
从 v0.19.0 , vite-plugin-pwa 增加了对@vite-pwa/assets-generator 的实验支持,以动态地服务、生成和注入 PWA 资产。
更多信息请查看 PWA Assets 生成器集成
新的 Vite 构建 从 v0.18.0
From v0.18.0, vite-plugin-pwa adds five new options to injectManifest option to allow customizing the service worker build output:
target: you can change thetargetbuild, the plugin will use the Vite's build.target option if not configuredminify: you can change theminifybuild, the plugin will use the Vite's build.minify option if not configuredsourcemap: you can change thesourcemapbuild, the plugin will use the Vite's build.sourcemap option if not configuredenableWorkboxModulesLogs: you can enable/disable theworkboxmodules log for a development or production build, by default, the plugin will useprocess.env.NODE_ENV(Workbox modules logs logic will be removed from the service worker inproductionbuild: dead code elimination)buildPlugins: you can add custom Rollup and/or Vite plugins to the service worker build
The new Vite build will allow you to use .env Files, the mode option in your PWA configuration will not be used when using injectManifest strategy, the plugin will use the Vite's mode option instead:
- use
import.meta.env.MODEto access the Vite mode inside your service worker. - use
import.meta.env.DEVorimport.meta.env.PRODto check if the service worker is running on development or production (equivalent toprocess.env.NODE_ENV), check Vite NODE_ENV and Modes docs.
提示
如果你在service worker中使用TypeScript访问 import.meta.env 变量,如果TypeScript提示错误,请将以下引用添加到service worker代码的开头:
/// <reference types="vite/client" />Rollup 4 和 Vite 5
Rollup 4 has changed the asset name layout format, it is using ascii letters (no encoding, including also dash and underscore), previous Rollup versions are using hex encoding:
- Using more characters can make the hash length shorter
- Using a faster hash algorithm can make hashing faster
- This is the PR that changed the hash algorithm: https://github.com/rollup/rollup/pull/5155
This change breaks the way vite-plugin-pwa build plugin builds the service worker, since it is using this regular expression /[.-][a-f0-9]{8}\./ for dontCacheBustURLsMatching in workbox and injectManifest options.
From version v0.17.0, vite-plugin-pwa configures dontCacheBustURLsMatching with a regular expression using the Vite's build.assetsDir option (defaults to assets):
workbox.dontCacheBustURLsMatching = /^assets\//injectManifest.dontCacheBustURLsMatching = /^assets\//
You can refer to this issue for more details about dontCacheBustURLsMatching: Workbox appears to be needlessly generating revision hashes.
@vite-pwa/vitepress
From version v0.3.0, @vite-pwa/vitepress configures dontCacheBustURLsMatching in a similar way to how vite-plugin-pwa does, but using the VitePress' assetsDir option (defaults to assets).
@vite-pwa/nuxt
From version v0.4.0, @vite-pwa/nuxt requires Vite 5 and Nuxt 3.9+.
From version v0.3.3, @vite-pwa/nuxt configures dontCacheBustURLsMatching in a similar way to how vite-plugin-pwa does, but using the Nuxt's app.buildAssetsDir option (defaults to _nuxt).
@vite-pwa/astro
From version v0.3.1, you can use import.meta.env.PUBLIC_ variables in your custom service worker when configured using .env files.
From version v0.2.0, @vite-pwa/astro configures dontCacheBustURLsMatching in a similar way to how vite-plugin-pwa does, but using the Astro's build.assets option (defaults to _astro).
@vite-pwa/sveltekit
From version v0.3.0, @vite-pwa/sveltekit supports SvelteKit 2 (should also support SvelteKit 1).
From version v0.2.9, @vite-pwa/sveltekit configures dontCacheBustURLsMatching in a similar way to how vite-plugin-pwa does, but using the Sveltkit's appDir option (defaults to _app).
警告
从版本 v0.2.0 , SvelteKitPWA 插件需要 SvelteKit 1.3.1 或以上版本。
如果你使用的是 v1.3.1 之前的 SvelteKit 版本,你应该使用 SvelteKitPWA 0.1.*插件版本 。
其他集成
如果您正在使用 vite-plugin-pwa 或与其他元框架的集成(îles),如果您正在使用 Vite 5 或 Rollup 4,请检查生成的 service worker,并在需要时适当更新 dontCacheBustURLsMatching 正则表达式。