@vite-pwa/tanstack 0.0.0-stage โ†’ 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-PRESENT Anthony Fu <https://github.com/antfu>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,145 @@
1
- # Temporary Holding Version
1
+ <p align='center'>
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/vite-pwa/.github/main/tanstack-hero-dark.svg" />
4
+ <img src="https://raw.githubusercontent.com/vite-pwa/.github/main/tanstack-hero.svg" alt="@vite-pwa/tanstack - Zero-config PWA for TanStack">
5
+ </picture>
6
+ </p>
2
7
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
8
+ <h1 align='center'>
9
+ Zero-config PWA for TanStack
10
+ </h1>
11
+
12
+ <p align='center'>
13
+ <a href='https://npmx.dev/package/@vite-pwa/tanstack' target="__blank">
14
+ <img src='https://img.shields.io/npm/v/@vite-pwa/tanstack?color=33A6B8&label=' alt="NPM version">
15
+ </a>
16
+ <a href="https://npmx.dev/package/@vite-pwa/tanstack" target="__blank">
17
+ <img alt="NPM Downloads" src="https://img.shields.io/npm/dm/@vite-pwa/tanstack?color=476582&label=">
18
+ </a>
19
+ <a href="https://unplugin-pwa.netlify.app/frameworks/tanstack" target="__blank">
20
+ <img src="https://img.shields.io/static/v1?label=&message=docs%20%26%20guides&color=2e859c" alt="Docs & Guides">
21
+ </a>
22
+ <br>
23
+ <a href="https://github.com/vite-pwa/tanstack" target="__blank">
24
+ <img alt="GitHub stars" src="https://img.shields.io/github/stars/vite-pwa/tanstack?style=social">
25
+ </a>
26
+ </p>
27
+
28
+ <br>
29
+
30
+ <p align="center">
31
+ <a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
32
+ <img src="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg" alt="Anthony Fu SVG sponsors image"/>
33
+ </a>
34
+ </p>
35
+
36
+ ## ๐Ÿš€ Features
37
+
38
+ - ๐Ÿ“– [**Documentation & guides**](https://unplugin-pwa.netlify.app/)
39
+ - ๐Ÿ‘Œ **Zero-Config**: sensible built-in default configs for common use cases
40
+ - ๐Ÿ”ฉ **Extensible**: expose the full ability to customize the behavior of the plugin
41
+ - ๐Ÿฆพ **Type Strong**: written in [TypeScript](https://www.typescriptlang.org/)
42
+ - ๐Ÿ”Œ **Offline Support**: generate service worker with offline support (via Workbox)
43
+ - โšก **Fully tree shakable**: client virtual modules are strictly optimized for Dead Code Elimination.
44
+ - ๐Ÿ“„ **Web Manifest**: auto-inject Web App Manifest and PWA assets seamlessly.
45
+ - ๐Ÿ’ฌ **Prompt for new content**: built-in support for Vanilla JavaScript, Vue 3, React, Svelte, SolidJS and Preact
46
+ - โš™๏ธ **Stale-while-revalidate**: automatic reload when new content is available
47
+ - โœจ **Static assets handling**: configure static assets for offline support
48
+ - ๐Ÿž **Development Support**: debug your custom service worker logic as you develop your application
49
+ - ๐Ÿ” **Inspector**: visually inspect your resolved configuration, web manifest and service worker during development, via middleware or [DevFrame](https://github.com/devframes/devframe)
50
+ - ๐Ÿงฉ **Modular**: use the ready-to-use plugins or compose your own integration from the building blocks in `@unplugin-pwa/core` and `@unplugin-pwa/vite`
51
+ - ๐Ÿ“ฆ **Universal Bundlers**: native integration with Vite, Rolldown, Webpack (WIP), Rspack (WIP), and Rsbuild (WIP).
52
+ - ๐Ÿ› ๏ธ **Meta-Frameworks**: seamless integration with [รฎles](https://github.com/ElMassimo/iles), [SvelteKit](https://github.com/sveltejs/kit), [VitePress](https://github.com/vuejs/vitepress), [Astro](https://github.com/withastro/astro), [Nuxt 3/4/5](https://github.com/nuxt/nuxt), [React Router](https://github.com/remix-run/react-router/), [TanStack](https://github.com/TanStack) and [Next](https://github.com/vercel/next.js/) (WIP).
53
+ - ๐Ÿ’ฅ **PWA Assets Generator**: generate all the PWA assets from a single command and a single source image
54
+ - ๐Ÿš€ **PWA Assets Integration**: serving, generating and injecting PWA Assets on the fly in your application
55
+
56
+ ## ๐Ÿ“ฆ Install
57
+
58
+ ```bash
59
+ npm i @vite-pwa/tanstack -D
60
+
61
+ # yarn
62
+ yarn add @vite-pwa/tanstack -D
63
+
64
+ # pnpm
65
+ pnpm add @vite-pwa/tanstack -D
66
+ ```
67
+
68
+ ## ๐Ÿฆ„ Usage
69
+
70
+ This package provides two different plugins depending on your setup: a standard plugin for TanStack on Vite (SPA), and a specific plugin for **TanStack Start** powered by Nitro.
71
+
72
+ ### TanStack Start (with Nitro v3)
73
+
74
+ If you are using TanStack Start, use the `TanStackNitroPWAPlugin` variant.
75
+
76
+ **โš ๏ธ Important Requirements:**
77
+ * **Nitro v3 RC:** You must use the latest Nitro v3 Release Candidate `3.0.261029-rc` (or newer) which includes the necessary lifecycle hook for the correct Service Worker pre-cache manifest generation.
78
+ * **Prerendering:** You **must** explicitly enable prerendering for your routes in the `nitro` configuration (`routeRules`) and in the `tanstackStart` plugin to add offline support. Without pre-rendering (e.g., generating the `index.html`), offline support will not work as the entry points will be missing from the SW precache manifest.
79
+
80
+ ```ts
81
+ // vite.config.ts
82
+ import { tanstackStart } from '@tanstack/react-start/plugin/vite'
83
+ import { TanStackNitroPWAPlugin } from '@vite-pwa/tanstack/vite/nitro'
84
+ import viteReact from '@vitejs/plugin-react'
85
+ import { nitro } from 'nitro/vite'
86
+ import { defineConfig } from 'vite'
87
+
88
+ export default defineConfig({
89
+ plugins: [
90
+ nitro({
91
+ baseURL: '/',
92
+ routeRules: {
93
+ // Prerendering must be enabled for offline support to work
94
+ '/': { prerender: true },
95
+ '/about': { prerender: true },
96
+ },
97
+ }),
98
+ tanstackStart({
99
+ prerender: {
100
+ enabled: true,
101
+ },
102
+ }),
103
+ viteReact(),
104
+ TanStackNitroPWAPlugin({
105
+ // Your PWA options
106
+ strategies: 'build-sw',
107
+ registerType: 'autoUpdate',
108
+ /* ... */
109
+ }),
110
+ ],
111
+ })
112
+ ```
113
+
114
+ ### TanStack (Standalone Vite)
115
+
116
+ If you are building a standard Single Page Application with Vite and TanStack (without Nitro/SSR), use the `TanStackVitePWAPlugin`.
117
+
118
+ ```ts
119
+ // vite.config.ts
120
+ import { TanStackVitePWAPlugin } from '@vite-pwa/tanstack'
121
+ import { defineConfig } from 'vite'
122
+
123
+ export default defineConfig({
124
+ plugins: [
125
+ // ... other plugins
126
+ TanStackVitePWAPlugin({
127
+ // Your PWA options
128
+ }),
129
+ ],
130
+ })
131
+ ```
132
+
133
+ Read the [๐Ÿ“– documentation](https://unplugin-pwa.netlify.app/frameworks/tanstack) for a complete guide on how to configure and use
134
+ this plugin.
135
+
136
+ ## ๐Ÿ‘€ Full config
137
+
138
+ Check out the type declaration [src/types.ts](https://github.com/vite-pwa/tanstack/blob/main/src/types.ts) and the following links for more details.
139
+
140
+ - [Web app manifests](https://developer.mozilla.org/en-US/docs/Web/Manifest)
141
+ - [Vite PWA Workbox](https://unplugin-pwa.netlify.app/vite-pwa-workbox/)
142
+
143
+ ## ๐Ÿ“„ License
144
+
145
+ [MIT](./LICENSE) License &copy; 2026-PRESENT [Anthony Fu](https://github.com/antfu)
@@ -0,0 +1,6 @@
1
+ import { t as TanStackPWAOptions } from "./types-CWf_OQK2.mjs";
2
+ import { VitePWAStrategy } from "@unplugin-pwa/core";
3
+ import { ExternalPWAOptions } from "@unplugin-pwa/vite/config/types";
4
+ import { SWType } from "@vite-pwa/workbox-build/types";
5
+ export type TanStackExternalPWAOptions<UserStrategy extends VitePWAStrategy, T extends SWType> = ExternalPWAOptions<UserStrategy, T, TanStackPWAOptions<UserStrategy, T>>;
6
+ export declare function definePwaConfig<UserStrategy extends VitePWAStrategy, T extends SWType>(config: Partial<TanStackExternalPWAOptions<UserStrategy, T>>): Partial<TanStackExternalPWAOptions<UserStrategy, T>>;
@@ -0,0 +1,5 @@
1
+ // src/config.ts
2
+ function definePwaConfig(config) {
3
+ return config;
4
+ }
5
+ export { definePwaConfig };
@@ -0,0 +1,22 @@
1
+ // src/create-manifest-transform.ts
2
+ const regexp = /\.html$/;
3
+ function createManifestTransform(base) {
4
+ return async (entries) => {
5
+ for (const e of entries) {
6
+ if (!e.url.endsWith(".html")) continue;
7
+ const url = e.url.startsWith("/") ? e.url.slice(1) : e.url;
8
+ if (url === "index.html") e.url = base;
9
+ else {
10
+ let parts = url.split("/");
11
+ if (parts.length > 1 && parts[parts.length - 1] === "index.html") parts = parts.slice(0, parts.length - 1);
12
+ else parts[parts.length - 1] = parts[parts.length - 1].replace(regexp, "");
13
+ e.url = parts.length > 1 ? parts.slice(0, parts.length - 1).join("/") : parts[0];
14
+ }
15
+ }
16
+ return {
17
+ manifest: entries,
18
+ warnings: []
19
+ };
20
+ };
21
+ }
22
+ export { createManifestTransform };
@@ -0,0 +1,18 @@
1
+ import { t as TanStackPWAContext } from "./create-pwa-context-BW54YalT.mjs";
2
+ import { t as TanStackPWAOptions } from "./types-CWf_OQK2.mjs";
3
+ import { VitePWAStrategy } from "@unplugin-pwa/core";
4
+ import { SWType } from "@vite-pwa/workbox-build/types";
5
+ import { Nitro } from "nitro/types";
6
+ export type TanStackNitroPWAContext<UserStrategy extends VitePWAStrategy, T extends SWType> = Omit<TanStackPWAContext<UserStrategy, T>, 'tanstack'> & {
7
+ tanstack: {
8
+ /**
9
+ * The nitro instance.
10
+ */
11
+ nitro: Nitro;
12
+ /**
13
+ * Alias for `build-sw` strategy: will use nitro alias once all modules configured.
14
+ */
15
+ buildSWAlias: Record<string, string>;
16
+ };
17
+ };
18
+ export declare function createTanStackNitroPWAContext<UserStrategy extends VitePWAStrategy, T extends SWType>(options: Partial<TanStackPWAOptions<UserStrategy, T>>): TanStackNitroPWAContext<UserStrategy, T>;
@@ -0,0 +1,9 @@
1
+ import { createTanStackPWAContext } from "./create-pwa-context.mjs";
2
+ // src/create-nitro-pwa-context.ts
3
+ function createTanStackNitroPWAContext(options) {
4
+ return Object.assign(createTanStackPWAContext(options), { tanstack: {
5
+ nitro: void 0,
6
+ buildSWAlias: {}
7
+ } });
8
+ }
9
+ export { createTanStackNitroPWAContext };
@@ -0,0 +1,11 @@
1
+ import { t as TanStackPWAOptions } from "./types-CWf_OQK2.mjs";
2
+ import { VitePWAPluginContext } from "@unplugin-pwa/vite/vite-context";
3
+ import { VitePWAStrategy } from "@unplugin-pwa/core";
4
+ import { SWType } from "@vite-pwa/workbox-build/types";
5
+ type TanStackPWAContext<UserStrategy extends VitePWAStrategy, T extends SWType> = VitePWAPluginContext<'vite', UserStrategy, T> & {
6
+ tanstack: {
7
+ buildSWAlias: Record<string, string>;
8
+ };
9
+ };
10
+ declare function createTanStackPWAContext<UserStrategy extends VitePWAStrategy, T extends SWType>(options: Partial<TanStackPWAOptions<UserStrategy, T>>): TanStackPWAContext<UserStrategy, T>;
11
+ export { createTanStackPWAContext as n, TanStackPWAContext as t };
@@ -0,0 +1,2 @@
1
+ import { n as createTanStackPWAContext, t as TanStackPWAContext } from "./create-pwa-context-BW54YalT.mjs";
2
+ export { TanStackPWAContext, createTanStackPWAContext };
@@ -0,0 +1,59 @@
1
+ import process from "node:process";
2
+ import { createVitePWAContext } from "@unplugin-pwa/vite/vite-context";
3
+ // src/create-pwa-context.ts
4
+ function createTanStackPWAContext(options) {
5
+ options.injectRegister = false;
6
+ const ctx = Object.assign(createVitePWAContext(true, options), {
7
+ hmrRequiresSwitcher: true,
8
+ inspectorRequiresViteDevtools: true,
9
+ tanstack: {
10
+ /**
11
+ * Alias for `build-sw` strategy if any, check `TanStackNitroPWAContext`.
12
+ */
13
+ buildSWAlias: {} }
14
+ });
15
+ ctx.configurePWAOptions = async (_forClient, resolvedConfig) => {
16
+ let options;
17
+ switch (ctx.strategy) {
18
+ case "generate-sw":
19
+ ctx.resolvedOptions.generateSW ??= {};
20
+ options = ctx.resolvedOptions.generateSW;
21
+ if (!("navigateFallback" in ctx.resolvedOptions.generateSW)) ctx.resolvedOptions.generateSW.navigateFallback = ctx.base ?? "/";
22
+ break;
23
+ case "inject-manifest":
24
+ ctx.resolvedOptions.injectManifest ??= {};
25
+ options = ctx.resolvedOptions.injectManifest;
26
+ break;
27
+ case "build-sw":
28
+ ctx.resolvedOptions.buildSW ??= {};
29
+ ctx.resolvedOptions.buildSW.alias = ctx.tanstack.buildSWAlias;
30
+ options = ctx.resolvedOptions.buildSW;
31
+ }
32
+ if (ctx.devEnvironment) return;
33
+ if (ctx.outDir.endsWith("/")) ctx.outDir = ctx.outDir.slice(0, ctx.outDir.length - 1);
34
+ ctx.resolvedOptions.outDir = ctx.outDir;
35
+ const immutableAssets = resolvedConfig.build.assetsDir ?? "assets/";
36
+ const cwd = process.cwd();
37
+ if (!options) return {
38
+ cwd,
39
+ outDir: ctx.outDir,
40
+ immutableAssets
41
+ };
42
+ options.globDirectory = ctx.outDir;
43
+ if (!("globPatterns" in options)) options.globPatterns = ["**/*.{js,css,html}"];
44
+ if (ctx.resolvedOptions.pwaAssets) ctx.resolvedOptions.pwaAssets.integration = {
45
+ baseUrl: ctx.base,
46
+ publicDir: resolvedConfig.publicDir || "public",
47
+ outDir: ctx.outDir
48
+ };
49
+ options.manifestTransforms ??= [];
50
+ options.manifestTransforms.push(await import("./create-manifest-transform-DJ5fnDyE.mjs").then(({ createManifestTransform }) => createManifestTransform(ctx.base || "/")));
51
+ return {
52
+ cwd,
53
+ outDir: ctx.outDir,
54
+ immutableAssets
55
+ };
56
+ };
57
+ return ctx;
58
+ }
59
+ export { createTanStackPWAContext };
@@ -0,0 +1,5 @@
1
+ import { t as TanStackPWAOptions } from "./types-CWf_OQK2.mjs";
2
+ import { VitePWAStrategy } from "@unplugin-pwa/core";
3
+ import { SWType } from "@vite-pwa/workbox-build/types";
4
+ import { PluginOption } from "vite";
5
+ export declare function TanStackVitePWAPlugin<UserStrategy extends VitePWAStrategy, T extends SWType>(options?: Partial<TanStackPWAOptions<UserStrategy, T>>): PluginOption[];
package/dist/index.mjs ADDED
@@ -0,0 +1,30 @@
1
+ import { createTanStackPWAContext } from "./create-pwa-context.mjs";
2
+ import { BuildSWPlugin } from "./vite/build-sw.mjs";
3
+ import { BuildPwaAssetsPlugin } from "@unplugin-pwa/vite/plugins/build-pwa-assets";
4
+ import { DevPlugin } from "@unplugin-pwa/vite/plugins/dev";
5
+ import { DevMiddlewarePlugin } from "@unplugin-pwa/vite/plugins/dev-middleware";
6
+ import { DevAssetsMiddlewarePlugin } from "@unplugin-pwa/vite/plugins/dev-pwa-assets-middleware";
7
+ import { DevtoolsPlugin } from "@unplugin-pwa/vite/plugins/devtools";
8
+ import { InfoPlugin } from "@unplugin-pwa/vite/plugins/info";
9
+ import { InspectorPlugin } from "@unplugin-pwa/vite/plugins/inspector";
10
+ import { MainPlugin } from "@unplugin-pwa/vite/plugins/main";
11
+ import { AssetsPlugin } from "@unplugin-pwa/vite/plugins/pwa-assets";
12
+ import { VirtualModulesPlugin } from "@unplugin-pwa/vite/plugins/virtual-modules";
13
+ // src/index.ts
14
+ function TanStackVitePWAPlugin(options = {}) {
15
+ const ctx = createTanStackPWAContext(options);
16
+ return [
17
+ MainPlugin(ctx),
18
+ VirtualModulesPlugin(ctx),
19
+ InfoPlugin(ctx),
20
+ DevPlugin(ctx),
21
+ DevMiddlewarePlugin(ctx),
22
+ DevAssetsMiddlewarePlugin(ctx),
23
+ AssetsPlugin(ctx),
24
+ BuildPwaAssetsPlugin(ctx),
25
+ BuildSWPlugin(ctx),
26
+ DevtoolsPlugin(ctx),
27
+ InspectorPlugin(ctx)
28
+ ];
29
+ }
30
+ export { TanStackVitePWAPlugin };
@@ -0,0 +1,15 @@
1
+ import process from "node:process";
2
+ import path from "node:path";
3
+ import { resolvePwaConfiguration } from "@unplugin-pwa/core/config";
4
+ import { normalizePath } from "@vite-pwa/workbox-build/utils/resolve-sw-names";
5
+ // src/vite/nitro/load-external-configuration.ts
6
+ async function loadExternalConfiguration(ctx) {
7
+ const resolvedOptions = await resolvePwaConfiguration(ctx.consumerOptions ?? {}, {
8
+ isDev: false,
9
+ isWrongInjectManifest: (swSrc) => {
10
+ return !(normalizePath(path.dirname(swSrc)) === normalizePath(path.resolve(process.cwd(), "public")));
11
+ }
12
+ });
13
+ Object.assign(ctx, { resolvedOptions });
14
+ }
15
+ export { loadExternalConfiguration };
@@ -0,0 +1,3 @@
1
+ import * as React from "react";
2
+ export declare function PWAAssets(): React.JSX.Element;
3
+ export declare function PWAManifest(): React.JSX.Element;
@@ -0,0 +1,23 @@
1
+ import * as React from "react";
2
+ import { pwaAssetsHead } from "virtual:pwa-assets/head";
3
+ import { pwaInfo } from "virtual:pwa-info";
4
+ // src/react-components/PWAManifest.tsx
5
+ function PWAManifest() {
6
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, pwaInfo ? /* @__PURE__ */ React.createElement("link", {
7
+ rel: "manifest",
8
+ href: pwaInfo.webManifest.href,
9
+ crossOrigin: pwaInfo.webManifest.useCredentials ? "use-credentials" : void 0
10
+ }) : null);
11
+ }
12
+ // src/react-components/PWAAssets.tsx
13
+ function PWAAssets() {
14
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, pwaAssetsHead.themeColor ? /* @__PURE__ */ React.createElement("meta", {
15
+ name: "theme-color",
16
+ content: pwaAssetsHead.themeColor.content
17
+ }) : null, pwaAssetsHead.links.map(({ href, ...link }) => /* @__PURE__ */ React.createElement("link", {
18
+ key: href,
19
+ href,
20
+ ...link
21
+ })), /* @__PURE__ */ React.createElement(PWAManifest, null));
22
+ }
23
+ export { PWAAssets, PWAManifest };
@@ -0,0 +1,6 @@
1
+ import { VitePWAOptions, VitePWAStrategy } from "@unplugin-pwa/core";
2
+ import { SWType } from "@vite-pwa/workbox-build/types";
3
+ type TanStackPWAOptions<UserStrategy extends VitePWAStrategy, T extends SWType> = Omit<VitePWAOptions<UserStrategy, T>, 'injectRegister'> & {
4
+ injectRegister: false;
5
+ };
6
+ export { TanStackPWAOptions as t };
@@ -0,0 +1,2 @@
1
+ import { t as TanStackPWAOptions } from "./types-CWf_OQK2.mjs";
2
+ export { TanStackPWAOptions };
@@ -0,0 +1,10 @@
1
+ import { t as TanStackPWAContext } from "../create-pwa-context-BW54YalT.mjs";
2
+ import { VitePWAStrategy } from "@unplugin-pwa/core";
3
+ import { SWType } from "@vite-pwa/workbox-build/types";
4
+ import { Plugin } from "vite";
5
+ /**
6
+ * Vite plugin to generate the service workers.
7
+ *
8
+ * @param ctx The Vite PWA plugin context.
9
+ */
10
+ export declare function BuildSWPlugin<UserStrategy extends VitePWAStrategy, T extends SWType>(ctx: TanStackPWAContext<UserStrategy, T>): Plugin;
@@ -0,0 +1,27 @@
1
+ // src/vite/build-sw.ts
2
+ /**
3
+ * Vite plugin to generate the service workers.
4
+ *
5
+ * @param ctx The Vite PWA plugin context.
6
+ */
7
+ function BuildSWPlugin(ctx) {
8
+ return {
9
+ name: "vite-pwa:tanstack:build:sw",
10
+ enforce: "post",
11
+ apply: "build",
12
+ sharedDuringBuild: true,
13
+ applyToEnvironment(environment) {
14
+ return environment.config.consumer === "client";
15
+ },
16
+ buildApp: {
17
+ order: "post",
18
+ async handler() {
19
+ if (!ctx.tanstack || "nitro" in ctx.tanstack) return;
20
+ const pwaAssetsGenerator = await ctx.pwaAssetsGenerator;
21
+ if (pwaAssetsGenerator) await pwaAssetsGenerator.generate();
22
+ if (!ctx.resolvedOptions.disable) await ctx.runBuild();
23
+ }
24
+ }
25
+ };
26
+ }
27
+ export { BuildSWPlugin };
@@ -0,0 +1,10 @@
1
+ import { TanStackNitroPWAContext } from "../../create-nitro-pwa-context.mjs";
2
+ import { VitePWAStrategy } from "@unplugin-pwa/core";
3
+ import { SWType } from "@vite-pwa/workbox-build/types";
4
+ import { PluginOption } from "vite";
5
+ /**
6
+ * Vite plugin to generate the service workers with Nitro v3.
7
+ *
8
+ * @param ctx The Vite PWA plugin context.
9
+ */
10
+ export declare function NitroConfigurationPlugin<UserStrategy extends VitePWAStrategy, T extends SWType>(ctx: TanStackNitroPWAContext<UserStrategy, T>): PluginOption;
@@ -0,0 +1,150 @@
1
+ import process from "node:process";
2
+ import path from "node:path";
3
+ // src/vite/nitro/config.ts
4
+ /**
5
+ * Vite plugin to generate the service workers with Nitro v3.
6
+ *
7
+ * @param ctx The Vite PWA plugin context.
8
+ */
9
+ function NitroConfigurationPlugin(ctx) {
10
+ return [{
11
+ name: "vite-pwa:tanstack:nitro-configuration:build",
12
+ enforce: "pre",
13
+ apply: "build",
14
+ sharedDuringBuild: true,
15
+ applyToEnvironment(environment) {
16
+ return environment.name === "client";
17
+ },
18
+ async configResolved(config) {
19
+ if (!ctx.tanstack.nitro || ctx.tanstack.nitro.options.dev) return;
20
+ ctx.viteConfig = config;
21
+ ctx.publicDir = config.publicDir || "public";
22
+ if (ctx.resolvedOptions.pwaAssets) ctx.resolvedOptions.pwaAssets.integration = {
23
+ baseUrl: ctx.base,
24
+ publicDir: ctx.publicDir,
25
+ outDir: ctx.outDir
26
+ };
27
+ const { preparePWAStrategy, preparePWAAssetsGenerator } = await import("@unplugin-pwa/core/helpers").then(({ preparePWAStrategy, preparePWAAssetsGenerator }) => ({
28
+ preparePWAStrategy,
29
+ preparePWAAssetsGenerator
30
+ }));
31
+ await preparePWAStrategy(ctx, process.cwd(), ctx.outDir, config.build.assetsDir ?? "assets");
32
+ preparePWAAssetsGenerator(ctx);
33
+ await ctx.hooks.callHook("context:ready");
34
+ },
35
+ nitro: prepareNitroModule(ctx, false)
36
+ }, {
37
+ name: "vite-pwa:tanstack:nitro-configuration:dev",
38
+ enforce: "pre",
39
+ apply: "serve",
40
+ applyToEnvironment(environment) {
41
+ return environment.name === "client";
42
+ },
43
+ configResolved(config) {
44
+ if (!ctx.tanstack.nitro || !ctx.tanstack.nitro.options.dev) return;
45
+ ctx.viteConfig = config;
46
+ },
47
+ nitro: prepareNitroModule(ctx, true)
48
+ }];
49
+ }
50
+ function prepareNitroModule(ctx, dev) {
51
+ return { setup(nitro) {
52
+ if (dev) {
53
+ if (!nitro.options.dev || ctx.tanstack.nitro) return;
54
+ nitro.hooks.hook("rollup:before", () => {
55
+ ctx.tanstack.buildSWAlias = nitro.options.alias;
56
+ });
57
+ ctx.tanstack.nitro = nitro;
58
+ return;
59
+ }
60
+ if (nitro.options.dev || ctx.tanstack.nitro) return;
61
+ ctx.externalConfigurationLoader = true;
62
+ ctx.tanstack.nitro = nitro;
63
+ nitro.hooks.hook("build:before", async () => {
64
+ const [loadExternalConfiguration, createManifestTransform, normalizeManifest, { extractSwDestNameFromSource, normalizePath, resolveSWNames }] = await Promise.all([
65
+ import("../../load-external-configuration-CSA2DKhO.mjs").then(({ loadExternalConfiguration }) => loadExternalConfiguration),
66
+ import("../../create-manifest-transform-DJ5fnDyE.mjs").then(({ createManifestTransform }) => createManifestTransform),
67
+ import("@unplugin-pwa/core/helpers").then(({ normalizeManifest }) => normalizeManifest),
68
+ import("@vite-pwa/workbox-build/utils/resolve-sw-names").then(({ extractSwDestNameFromSource, normalizePath, resolveSWNames }) => ({
69
+ extractSwDestNameFromSource,
70
+ normalizePath,
71
+ resolveSWNames
72
+ }))
73
+ ]);
74
+ await loadExternalConfiguration(ctx);
75
+ ctx.outDir = nitro.options.output.publicDir;
76
+ if (ctx.outDir.endsWith("/")) ctx.outDir = ctx.outDir.slice(0, ctx.outDir.length - 1);
77
+ ctx.consumerOptions.outDir = ctx.outDir;
78
+ ctx.resolvedOptions.outDir = ctx.outDir;
79
+ ctx.rootDir = process.cwd();
80
+ const { base = nitro.options.baseURL || "/", scope, buildBase } = ctx.resolvedOptions;
81
+ ctx.resolvedOptions.scope = scope || base;
82
+ ctx.resolvedOptions.base = buildBase ?? base;
83
+ ctx.resolvedOptions.buildBase = ctx.resolvedOptions.base;
84
+ ctx.strategy = ctx.resolvedOptions.strategy;
85
+ ctx.useImportRegister = false;
86
+ ctx.base = ctx.resolvedOptions.base;
87
+ if (!ctx.resolvedOptions.disable) {
88
+ let swSrc;
89
+ let options;
90
+ let filename;
91
+ switch (ctx.strategy) {
92
+ case "generate-sw":
93
+ ctx.resolvedOptions.generateSW ??= {};
94
+ options = ctx.resolvedOptions.generateSW;
95
+ swSrc = "x";
96
+ filename = ctx.resolvedOptions.generateSW.swDest;
97
+ break;
98
+ case "inject-manifest":
99
+ ctx.resolvedOptions.injectManifest ??= {};
100
+ options = ctx.resolvedOptions.injectManifest;
101
+ swSrc = ctx.resolvedOptions.injectManifest.swSrc;
102
+ filename = ctx.consumerOptions.filename || extractSwDestNameFromSource(swSrc);
103
+ ctx.resolvedOptions.injectManifest.swDest = filename;
104
+ break;
105
+ case "build-sw":
106
+ ctx.resolvedOptions.buildSW ??= {};
107
+ options = ctx.resolvedOptions.buildSW;
108
+ swSrc = ctx.resolvedOptions.buildSW.swSrc;
109
+ filename = ctx.consumerOptions.filename || extractSwDestNameFromSource(swSrc);
110
+ ctx.resolvedOptions.buildSW.swDest = filename;
111
+ }
112
+ nitro.options.routeRules = nitro.options.routeRules || {};
113
+ nitro.options.routes = nitro.options.routes || {};
114
+ if (options) {
115
+ options.globDirectory = normalizePath(path.relative(process.cwd(), ctx.outDir));
116
+ options.manifestTransforms ??= [];
117
+ options.manifestTransforms.push(createManifestTransform(ctx.base || "/"));
118
+ }
119
+ if (options) {
120
+ const { swDest, classicSWDest, moduleSWDest } = resolveSWNames(filename, swSrc, ctx.strategy === "generate-sw");
121
+ ctx.swNames = {
122
+ hasNames: true,
123
+ name: swDest,
124
+ classic: classicSWDest,
125
+ module: moduleSWDest
126
+ };
127
+ if (ctx.resolvedOptions.swType === "classic-and-module") {
128
+ nitro.options.routeRules[`${path.basename(ctx.swNames.classic)}`] = { headers: { "Cache-Control": "public, max-age=0, must-revalidate" } };
129
+ nitro.options.routeRules[`${path.basename(ctx.swNames.module)}`] = { headers: { "Cache-Control": "public, max-age=0, must-revalidate" } };
130
+ } else nitro.options.routeRules[`${path.basename(ctx.swNames.name)}`] = { headers: { "Cache-Control": "public, max-age=0, must-revalidate" } };
131
+ }
132
+ }
133
+ if (ctx.resolvedOptions.manifest) nitro.options.routeRules[`${ctx.resolvedOptions.manifestFilename ?? "manifest.webmanifest"}`] = { headers: {
134
+ "Content-Type": "application/manifest+json",
135
+ "Cache-Control": "public, max-age=0, must-revalidate"
136
+ } };
137
+ normalizeManifest(ctx);
138
+ });
139
+ nitro.hooks.hook("rollup:before", () => {
140
+ ctx.tanstack.buildSWAlias = nitro.options.alias;
141
+ if (ctx.strategy === "build-sw") ctx.resolvedOptions.buildSW.alias = nitro.options.alias;
142
+ });
143
+ nitro.hooks.hook("vite:compile:before", async () => {
144
+ const pwaAssetsGenerator = await ctx.pwaAssetsGenerator;
145
+ if (pwaAssetsGenerator) await pwaAssetsGenerator.generate();
146
+ if (!ctx.resolvedOptions.disable) await ctx.runBuild();
147
+ });
148
+ } };
149
+ }
150
+ export { NitroConfigurationPlugin };
@@ -0,0 +1,5 @@
1
+ import { t as TanStackPWAOptions } from "../types-CWf_OQK2.mjs";
2
+ import { VitePWAStrategy } from "@unplugin-pwa/core";
3
+ import { SWType } from "@vite-pwa/workbox-build/types";
4
+ import { PluginOption } from "vite";
5
+ export declare function TanStackNitroPWAPlugin<UserStrategy extends VitePWAStrategy, T extends SWType>(options?: Partial<TanStackPWAOptions<UserStrategy, T>>): PluginOption[];
@@ -0,0 +1,30 @@
1
+ import { createTanStackNitroPWAContext } from "../create-nitro-pwa-context.mjs";
2
+ import { NitroConfigurationPlugin } from "./nitro/config.mjs";
3
+ import { BuildPwaAssetsPlugin } from "@unplugin-pwa/vite/plugins/build-pwa-assets";
4
+ import { DevPlugin } from "@unplugin-pwa/vite/plugins/dev";
5
+ import { DevMiddlewarePlugin } from "@unplugin-pwa/vite/plugins/dev-middleware";
6
+ import { DevAssetsMiddlewarePlugin } from "@unplugin-pwa/vite/plugins/dev-pwa-assets-middleware";
7
+ import { DevtoolsPlugin } from "@unplugin-pwa/vite/plugins/devtools";
8
+ import { InfoPlugin } from "@unplugin-pwa/vite/plugins/info";
9
+ import { InspectorPlugin } from "@unplugin-pwa/vite/plugins/inspector";
10
+ import { MainPlugin } from "@unplugin-pwa/vite/plugins/main";
11
+ import { AssetsPlugin } from "@unplugin-pwa/vite/plugins/pwa-assets";
12
+ import { VirtualModulesPlugin } from "@unplugin-pwa/vite/plugins/virtual-modules";
13
+ // src/vite/nitro.ts
14
+ function TanStackNitroPWAPlugin(options = {}) {
15
+ const ctx = createTanStackNitroPWAContext(options);
16
+ return [
17
+ NitroConfigurationPlugin(ctx),
18
+ MainPlugin(ctx),
19
+ VirtualModulesPlugin(ctx),
20
+ InfoPlugin(ctx),
21
+ DevPlugin(ctx),
22
+ DevMiddlewarePlugin(ctx),
23
+ DevAssetsMiddlewarePlugin(ctx),
24
+ AssetsPlugin(ctx),
25
+ BuildPwaAssetsPlugin(ctx),
26
+ DevtoolsPlugin(ctx),
27
+ InspectorPlugin(ctx)
28
+ ];
29
+ }
30
+ export { TanStackNitroPWAPlugin };
package/package.json CHANGED
@@ -1,6 +1,109 @@
1
1
  {
2
2
  "name": "@vite-pwa/tanstack",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "description": "Zero-config PWA for TanStack",
6
+ "author": "antfu <anthonyfu117@hotmail.com>",
7
+ "license": "MIT",
8
+ "funding": "https://github.com/sponsors/antfu",
9
+ "homepage": "https://github.com/vite-pwa/tanstack#readme",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/vite-pwa/tanstack.git"
13
+ },
14
+ "bugs": "https://github.com/vite-pwa/tanstack/issues",
15
+ "keywords": [
16
+ "tanstack",
17
+ "tanstack start",
18
+ "workbox",
19
+ "pwa",
20
+ "vite",
21
+ "nitro",
22
+ "unplugin-pwa"
23
+ ],
24
+ "sideEffects": false,
25
+ "exports": {
26
+ ".": "./dist/index.mjs",
27
+ "./config": "./dist/config.mjs",
28
+ "./types": {
29
+ "types": "./dist/types.d.mts"
30
+ },
31
+ "./create-nitro-pwa-context": "./dist/create-nitro-pwa-context.mjs",
32
+ "./create-pwa-context": "./dist/create-pwa-context.mjs",
33
+ "./vite/build-sw": "./dist/vite/build-sw.mjs",
34
+ "./vite/nitro": "./dist/vite/nitro.mjs",
35
+ "./vite/nitro/config": "./dist/vite/nitro/config.mjs",
36
+ "./react-components": "./dist/react-components.mjs",
37
+ "./package.json": "./package.json"
38
+ },
39
+ "types": "dist/index.d.mts",
40
+ "files": [
41
+ "dist"
42
+ ],
43
+ "engines": {
44
+ "node": ">=22.14.0"
45
+ },
46
+ "peerDependencies": {
47
+ "@vite-pwa/assets-generator": "^1.0.0 || ^2.0.0",
48
+ "magicast": "^0.5.0",
49
+ "nitro": "^3.0.0-0",
50
+ "rolldown": "^1.0.0-0",
51
+ "vite": "^7.0.0 || ^8.0.0"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "@vite-pwa/assets-generator": {
55
+ "optional": true
56
+ },
57
+ "magicast": {
58
+ "optional": true
59
+ },
60
+ "nitro": {
61
+ "optional": true
62
+ },
63
+ "rolldown": {
64
+ "optional": true
65
+ },
66
+ "vite": {
67
+ "optional": true
68
+ }
69
+ },
70
+ "dependencies": {
71
+ "@unplugin-pwa/core": "^0.0.3",
72
+ "@unplugin-pwa/inspector": "^0.0.3",
73
+ "@unplugin-pwa/vite": "^0.0.3",
74
+ "@vite-pwa/workbox-build": "^8.0.13",
75
+ "@vite-pwa/workbox-swkit": "^8.0.13",
76
+ "@vite-pwa/workbox-window": "^8.0.13"
77
+ },
78
+ "devDependencies": {
79
+ "@antfu/eslint-config": "^10.0.0",
80
+ "@antfu/ni": "^25.0.0",
81
+ "@arethetypeswrong/core": "^0.18.5",
82
+ "@types/debug": "^4.1.13",
83
+ "@types/node": "24.19.2",
84
+ "@types/react": "^19.2.0",
85
+ "@vite-pwa/assets-generator": "^2.0.0",
86
+ "@vitejs/devtools": "^0.7.6",
87
+ "eslint": "^10.13.0",
88
+ "eslint-plugin-antfu": "^3.2.3",
89
+ "https-localhost": "4.7.2",
90
+ "nitro": "^3.0.261029-rc",
91
+ "publint": "^0.3.25",
92
+ "react": "^19.2.0",
93
+ "taze": "21.1.0",
94
+ "tsdown": "^0.23.1",
95
+ "typescript": "~6.0.3",
96
+ "vite": "^8.3.5"
97
+ },
98
+ "publishConfig": {
99
+ "access": "public",
100
+ "provenance": true
101
+ },
102
+ "scripts": {
103
+ "build": "tsdown",
104
+ "lint": "eslint .",
105
+ "lint:fix": "pnpm lint --fix",
106
+ "update:deps": "taze -I",
107
+ "test:typecheck": "tsc --noEmit"
108
+ }
6
109
  }