@serwist/next 9.3.1 → 9.4.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/dist/index.config.js +3 -3
- package/dist/index.react.d.ts +7 -1
- package/dist/index.react.d.ts.map +1 -1
- package/dist/index.react.js +8 -13
- package/package.json +9 -9
- package/src/index.config.ts +3 -3
- package/src/index.react.tsx +13 -7
package/dist/index.config.js
CHANGED
|
@@ -12,8 +12,8 @@ const generateGlobPatterns = (distDir)=>[
|
|
|
12
12
|
const __require = createRequire(import.meta.url);
|
|
13
13
|
const loadNextConfig = __require("next/dist/server/config.js");
|
|
14
14
|
const serwist = async (options)=>{
|
|
15
|
-
const
|
|
16
|
-
const nextPhase =
|
|
15
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
16
|
+
const nextPhase = isDev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD;
|
|
17
17
|
const config = await loadNextConfig.default(nextPhase, process.cwd(), {
|
|
18
18
|
silent: false
|
|
19
19
|
});
|
|
@@ -35,7 +35,7 @@ const serwist = async (options)=>{
|
|
|
35
35
|
}
|
|
36
36
|
return {
|
|
37
37
|
dontCacheBustURLsMatching: new RegExp(`^${distDir}static/`),
|
|
38
|
-
disablePrecacheManifest:
|
|
38
|
+
disablePrecacheManifest: isDev,
|
|
39
39
|
...cliOptions,
|
|
40
40
|
globDirectory,
|
|
41
41
|
globPatterns: [
|
package/dist/index.react.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type ReactNode } from "react";
|
|
|
3
3
|
import { useSerwist } from "./lib/context.js";
|
|
4
4
|
export interface SerwistProviderProps {
|
|
5
5
|
swUrl: string;
|
|
6
|
+
disable?: boolean;
|
|
6
7
|
register?: boolean;
|
|
7
8
|
cacheOnNavigation?: boolean;
|
|
8
9
|
reloadOnOnline?: boolean;
|
|
@@ -14,6 +15,11 @@ declare global {
|
|
|
14
15
|
serwist: Serwist;
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
/**
|
|
19
|
+
* `@serwist/window` provider for Next.js apps.
|
|
20
|
+
* @param options
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export declare function SerwistProvider({ swUrl, disable, register, cacheOnNavigation, reloadOnOnline, options, children, }: SerwistProviderProps): import("react").JSX.Element;
|
|
18
24
|
export { useSerwist };
|
|
19
25
|
//# sourceMappingURL=index.react.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.react.d.ts","sourceRoot":"","sources":["../src/index.react.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAkB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,EAAE,OAAO,CAAC;KAClB;CACF;AAED,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,QAAe,EACf,iBAAwB,EACxB,cAAqB,EACrB,OAAO,EACP,QAAQ,GACT,EAAE,oBAAoB,+
|
|
1
|
+
{"version":3,"file":"index.react.d.ts","sourceRoot":"","sources":["../src/index.react.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAkB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,EAAE,OAAO,CAAC;KAClB;CACF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,OAAe,EACf,QAAe,EACf,iBAAwB,EACxB,cAAqB,EACrB,OAAO,EACP,QAAQ,GACT,EAAE,oBAAoB,+BAuDtB;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/index.react.js
CHANGED
|
@@ -12,28 +12,23 @@ const useSerwist = ()=>{
|
|
|
12
12
|
return context;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
function SerwistProvider({ swUrl, register = true, cacheOnNavigation = true, reloadOnOnline = true, options, children }) {
|
|
15
|
+
function SerwistProvider({ swUrl, disable = false, register = true, cacheOnNavigation = true, reloadOnOnline = true, options, children }) {
|
|
16
16
|
const [serwist] = useState(()=>{
|
|
17
17
|
if (typeof window === "undefined") return null;
|
|
18
|
+
if (disable) return null;
|
|
19
|
+
const scope = options?.scope || "/";
|
|
18
20
|
if (!(window.serwist && window.serwist instanceof Serwist) && "serviceWorker" in navigator) {
|
|
19
21
|
window.serwist = new Serwist(swUrl, {
|
|
20
22
|
...options,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
scope,
|
|
24
|
+
type: options?.type || "module"
|
|
23
25
|
});
|
|
26
|
+
if (register && !isCurrentPageOutOfScope(scope)) {
|
|
27
|
+
void window.serwist.register();
|
|
28
|
+
}
|
|
24
29
|
}
|
|
25
30
|
return window.serwist ?? null;
|
|
26
31
|
});
|
|
27
|
-
useEffect(()=>{
|
|
28
|
-
const scope = options?.scope || "/";
|
|
29
|
-
if (register && !isCurrentPageOutOfScope(scope)) {
|
|
30
|
-
void serwist?.register();
|
|
31
|
-
}
|
|
32
|
-
}, [
|
|
33
|
-
register,
|
|
34
|
-
options?.scope,
|
|
35
|
-
serwist?.register
|
|
36
|
-
]);
|
|
37
32
|
useEffect(()=>{
|
|
38
33
|
const cacheUrls = async (url)=>{
|
|
39
34
|
if (!window.navigator.onLine || !url) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/next",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A module that integrates Serwist into your Next.js application.",
|
|
6
6
|
"files": [
|
|
@@ -80,10 +80,10 @@
|
|
|
80
80
|
"kolorist": "1.8.0",
|
|
81
81
|
"semver": "7.7.3",
|
|
82
82
|
"zod": "4.2.1",
|
|
83
|
-
"@serwist/build": "9.
|
|
84
|
-
"@serwist/webpack-plugin": "9.
|
|
85
|
-
"@serwist/window": "9.
|
|
86
|
-
"serwist": "9.
|
|
83
|
+
"@serwist/build": "9.4.1",
|
|
84
|
+
"@serwist/webpack-plugin": "9.4.1",
|
|
85
|
+
"@serwist/window": "9.4.1",
|
|
86
|
+
"serwist": "9.4.1"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
89
|
"@types/node": "25.0.3",
|
|
@@ -96,15 +96,15 @@
|
|
|
96
96
|
"type-fest": "5.3.1",
|
|
97
97
|
"typescript": "5.9.3",
|
|
98
98
|
"webpack": "5.104.1",
|
|
99
|
-
"@serwist/cli": "9.
|
|
100
|
-
"@serwist/configs": "9.
|
|
101
|
-
"@serwist/utils": "9.
|
|
99
|
+
"@serwist/cli": "9.4.1",
|
|
100
|
+
"@serwist/configs": "9.4.1",
|
|
101
|
+
"@serwist/utils": "9.4.1"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
104
|
"next": ">=14.0.0",
|
|
105
105
|
"react": ">=18.0.0",
|
|
106
106
|
"typescript": ">=5.0.0",
|
|
107
|
-
"@serwist/cli": "9.
|
|
107
|
+
"@serwist/cli": "^9.4.1"
|
|
108
108
|
},
|
|
109
109
|
"peerDependenciesMeta": {
|
|
110
110
|
"@serwist/cli": {
|
package/src/index.config.ts
CHANGED
|
@@ -9,8 +9,8 @@ import { generateGlobPatterns } from "./lib/config/utils.js";
|
|
|
9
9
|
import loadNextConfig = require("next/dist/server/config.js");
|
|
10
10
|
|
|
11
11
|
export const serwist = async (options: SerwistOptions): Promise<BuildOptions> => {
|
|
12
|
-
const
|
|
13
|
-
const nextPhase =
|
|
12
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
13
|
+
const nextPhase = isDev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD;
|
|
14
14
|
const config = await loadNextConfig.default(nextPhase, process.cwd(), {
|
|
15
15
|
silent: false,
|
|
16
16
|
});
|
|
@@ -27,7 +27,7 @@ export const serwist = async (options: SerwistOptions): Promise<BuildOptions> =>
|
|
|
27
27
|
}
|
|
28
28
|
return {
|
|
29
29
|
dontCacheBustURLsMatching: new RegExp(`^${distDir}static/`),
|
|
30
|
-
disablePrecacheManifest:
|
|
30
|
+
disablePrecacheManifest: isDev,
|
|
31
31
|
...cliOptions,
|
|
32
32
|
globDirectory,
|
|
33
33
|
globPatterns: [
|
package/src/index.react.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import { SerwistContext, useSerwist } from "./lib/context.js";
|
|
|
5
5
|
|
|
6
6
|
export interface SerwistProviderProps {
|
|
7
7
|
swUrl: string;
|
|
8
|
+
disable?: boolean;
|
|
8
9
|
register?: boolean;
|
|
9
10
|
cacheOnNavigation?: boolean;
|
|
10
11
|
reloadOnOnline?: boolean;
|
|
@@ -18,8 +19,14 @@ declare global {
|
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
/**
|
|
23
|
+
* `@serwist/window` provider for Next.js apps.
|
|
24
|
+
* @param options
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
21
27
|
export function SerwistProvider({
|
|
22
28
|
swUrl,
|
|
29
|
+
disable = false,
|
|
23
30
|
register = true,
|
|
24
31
|
cacheOnNavigation = true,
|
|
25
32
|
reloadOnOnline = true,
|
|
@@ -28,17 +35,16 @@ export function SerwistProvider({
|
|
|
28
35
|
}: SerwistProviderProps) {
|
|
29
36
|
const [serwist] = useState(() => {
|
|
30
37
|
if (typeof window === "undefined") return null;
|
|
38
|
+
if (disable) return null;
|
|
39
|
+
const scope = options?.scope || "/";
|
|
31
40
|
if (!(window.serwist && window.serwist instanceof Serwist) && "serviceWorker" in navigator) {
|
|
32
|
-
window.serwist = new Serwist(swUrl, { ...options, type: options?.type || "module"
|
|
41
|
+
window.serwist = new Serwist(swUrl, { ...options, scope, type: options?.type || "module" });
|
|
42
|
+
if (register && !isCurrentPageOutOfScope(scope)) {
|
|
43
|
+
void window.serwist.register();
|
|
44
|
+
}
|
|
33
45
|
}
|
|
34
46
|
return window.serwist ?? null;
|
|
35
47
|
});
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
const scope = options?.scope || "/";
|
|
38
|
-
if (register && !isCurrentPageOutOfScope(scope)) {
|
|
39
|
-
void serwist?.register();
|
|
40
|
-
}
|
|
41
|
-
}, [register, options?.scope, serwist?.register]);
|
|
42
48
|
useEffect(() => {
|
|
43
49
|
const cacheUrls = async (url?: string | URL | null | undefined) => {
|
|
44
50
|
if (!window.navigator.onLine || !url) {
|