diff --git a/.changeset/soft-schools-battle.md b/.changeset/soft-schools-battle.md
new file mode 100644
index 00000000..52e6ae76
--- /dev/null
+++ b/.changeset/soft-schools-battle.md
@@ -0,0 +1,7 @@
+---
+"@ducanh2912/next-pwa": minor
+---
+
+feat: added `watchWorkersInDev`
+
+- Note that this feature is disabled by default, and can be enabled by setting `PluginOptions.watchWorkersInDev` to `true`. After a change is detected and `webpack` rebuilds the custom worker, you have to reload the page for it to take effect.
diff --git a/.changeset/weak-tables-roll.md b/.changeset/weak-tables-roll.md
new file mode 100644
index 00000000..883c5b29
--- /dev/null
+++ b/.changeset/weak-tables-roll.md
@@ -0,0 +1,7 @@
+---
+"@ducanh2912/next-pwa": minor
+---
+
+feat: added `.webm` to `defaultCache`'s `static-video-assets`
+
+- I think it'd be nice to support this extension as well, and this shouldn't cause a breaking change (if there is another entry that matches `.webm` files in `workboxOptions.runtimeCaching` and `extendDefaultRuntimeCaching`, then Workbox will still pick that entry).
diff --git a/.github/ISSUE_TEMPLATE/2-feature-request.yaml b/.github/ISSUE_TEMPLATE/2-feature-request.yaml
index e6896611..1161683c 100644
--- a/.github/ISSUE_TEMPLATE/2-feature-request.yaml
+++ b/.github/ISSUE_TEMPLATE/2-feature-request.yaml
@@ -2,6 +2,8 @@ name: Feature request
description: Create a feature request
title: "[Feature request]: "
labels: ["feature-request", "triage"]
+assignees:
+ - DuCanhGH
body:
- type: markdown
attributes:
diff --git a/docs/content/next-pwa/configuring.mdx b/docs/content/next-pwa/configuring.mdx
index 72bf5696..bae523d6 100644
--- a/docs/content/next-pwa/configuring.mdx
+++ b/docs/content/next-pwa/configuring.mdx
@@ -95,6 +95,8 @@ export default withPWA({
- `reloadOnOnline` — Reload the app when it has gone back online.
+- `watchWorkersInDev` — Watch certain workers for file changes in development mode. This currently includes the custom worker.
+
## Other options
`next-pwa` uses `workbox-webpack-plugin` under the hood, other options can be found in the documentation for [GenerateSW](https://developer.chrome.com/docs/workbox/modules/workbox-webpack-plugin/#generatesw-plugin) and
diff --git a/examples/custom-worker/shared/utils/index.ts b/examples/custom-worker/shared/utils/index.ts
index 3c0c1ef9..031cf0f6 100644
--- a/examples/custom-worker/shared/utils/index.ts
+++ b/examples/custom-worker/shared/utils/index.ts
@@ -1,5 +1,5 @@
-export function util(message: string) {
- console.log("Hello from util.");
+export function utils(message: string) {
+ console.log("Hello from utils.");
console.log("es6+ syntax test:");
// eslint-disable-next-line prefer-const
let foo = { message: message };
diff --git a/examples/custom-worker/worker/index.ts b/examples/custom-worker/worker/index.ts
index eb91ac41..49d87dc4 100644
--- a/examples/custom-worker/worker/index.ts
+++ b/examples/custom-worker/worker/index.ts
@@ -1,5 +1,5 @@
import { message } from "@shared/constants.ts";
-import { util } from "@shared/utils/index.ts";
+import { utils } from "@shared/utils/index.ts";
declare const self: ServiceWorkerGlobalScope;
@@ -8,7 +8,7 @@ declare const self: ServiceWorkerGlobalScope;
//
// self.__WB_DISABLE_DEV_LOGS = true
-util(message);
+utils(message);
// listen to message event from window
self.addEventListener("message", (event) => {
diff --git a/packages/next-pwa/src/cache.ts b/packages/next-pwa/src/cache.ts
index a5fe24eb..a4af8a99 100644
--- a/packages/next-pwa/src/cache.ts
+++ b/packages/next-pwa/src/cache.ts
@@ -81,7 +81,7 @@ const defaultCache: RuntimeCaching[] = [
},
},
{
- urlPattern: /\.(?:mp4)$/i,
+ urlPattern: /\.(?:mp4|webm)$/i,
handler: "CacheFirst",
options: {
rangeRequests: true,
diff --git a/packages/next-pwa/src/index.ts b/packages/next-pwa/src/index.ts
index 3f96c285..d2a9795d 100644
--- a/packages/next-pwa/src/index.ts
+++ b/packages/next-pwa/src/index.ts
@@ -87,6 +87,7 @@ const withPWAInit = (
extendDefaultRuntimeCaching = false,
swcMinify = nextConfig.swcMinify ?? nextDefConfig?.swcMinify ?? false,
browserslist = "chrome >= 56",
+ watchWorkersInDev = false,
} = pluginOptions;
if (typeof nextConfig.webpack === "function") {
@@ -150,6 +151,7 @@ const withPWAInit = (
setDefaultContext("shouldMinify", !dev);
setDefaultContext("useSwcMinify", swcMinify);
setDefaultContext("browserslist", browserslist);
+ setDefaultContext("devWatchWorkers", watchWorkersInDev);
const _dest = path.join(options.dir, dest);
const _cwdest = path.join(options.dir, customWorkerDest);
diff --git a/packages/next-pwa/src/resolve-workbox-plugin.ts b/packages/next-pwa/src/resolve-workbox-plugin.ts
index a749e606..eea55f74 100644
--- a/packages/next-pwa/src/resolve-workbox-plugin.ts
+++ b/packages/next-pwa/src/resolve-workbox-plugin.ts
@@ -9,7 +9,7 @@ import { resolveRuntimeCaching } from "./resolve-runtime-caching.js";
import type { WorkboxCommon } from "./resolve-workbox-common.js";
import type { PluginOptions } from "./types.js";
import { isInjectManifestConfig, overrideAfterCalledMethod } from "./utils.js";
-import { NextPWAContext } from "./webpack-builders/context.js";
+import { nextPWAContext } from "./webpack-builders/context.js";
type PluginCompleteOptions = Required<
Pick
@@ -40,17 +40,17 @@ export const resolveWorkboxPlugin = ({
hasFallbacks: boolean;
} & PluginCompleteOptions) => {
if (!workboxOptions.babelPresetEnvTargets) {
- switch (typeof NextPWAContext.browserslist) {
+ switch (typeof nextPWAContext.browserslist) {
case "string":
- workboxOptions.babelPresetEnvTargets = [NextPWAContext.browserslist];
+ workboxOptions.babelPresetEnvTargets = [nextPWAContext.browserslist];
break;
case "object": {
- if (Array.isArray(NextPWAContext.browserslist)) {
- workboxOptions.babelPresetEnvTargets = NextPWAContext.browserslist;
+ if (Array.isArray(nextPWAContext.browserslist)) {
+ workboxOptions.babelPresetEnvTargets = nextPWAContext.browserslist;
} else {
workboxOptions.babelPresetEnvTargets = [];
for (const [browser, minimumVersion] of Object.entries(
- NextPWAContext.browserslist
+ nextPWAContext.browserslist
)) {
workboxOptions.babelPresetEnvTargets.push(
`${browser} >= ${minimumVersion}`
diff --git a/packages/next-pwa/src/types.ts b/packages/next-pwa/src/types.ts
index e8c8c055..c12e07c3 100644
--- a/packages/next-pwa/src/types.ts
+++ b/packages/next-pwa/src/types.ts
@@ -4,59 +4,66 @@ import type { BrowserslistOptions, WorkboxTypes } from "./private-types.js";
export interface PluginOptions {
/**
- * Whether `next-pwa` should be disabled.
+ * Cache every `` and `` on frontend navigation.
+ * Requires `cacheOnFrontEndNav` to be enabled.
* @default false
*/
- disable?: boolean;
+ aggressiveFrontEndNavCaching?: boolean;
/**
- * Allow this plugin to automatically register the service worker for you. Set
- * this to `false` if you want to register the service worker yourself, which
- * can be done by running `window.workbox.register()` in
- * `componentDidMount` or `useEffect`.
+ * Configure supported browsers using Browserslist.
+ * @default "chrome >= 56"
+ */
+ browserslist?: BrowserslistOptions;
+ /**
+ * One or more specifiers used to exclude assets from the precache manifest.
+ * This is interpreted following the same rules as Webpack's standard `exclude`
+ * option. Relative to `.next/static` or your custom build folder. Defaults to
+ * [].
* @example
- * ```tsx
- * // app/register-pwa.tsx
- * "use client";
- * import { useEffect } from "react";
- * import type { Workbox } from "workbox-window";
- *
- * declare global {
- * interface Window {
- * workbox: Workbox;
- * }
- * }
- *
- * export default function RegisterPWA() {
- * useEffect(() => {
- * if ("serviceWorker" in navigator && window.workbox !== undefined) {
- * window.workbox.register();
- * }
- * }, []);
- * return <>>;
- * }
- *
- * // app/layout.tsx
- * import RegisterPWA from "./register-pwa";
- *
- * export default function RootLayout({
- * children,
- * }: {
- * children: React.ReactNode;
- * }) {
- * return (
- *
- *
- *
- *
- * {children}
- *
- *
- * );
- * }
+ * ```ts
+ * [/chunks\/images\/.*$/];
* ```
+ * @default
+ * ```ts
+ * [];
+ * ```
+ */
+ buildExcludes?: GenerateSWConfig["exclude"];
+ /**
+ * Enable additional route caching when users navigate through pages with
+ * `next/link`. This improves user experience in some cases but it
+ * also adds some overhead because of additional network calls.
+ * @default false
+ */
+ cacheOnFrontEndNav?: boolean;
+ /**
+ * Turn on caching for the start URL. [Discussion on use cases for this
+ * option](https://github.com/shadowwalker/next-pwa/pull/296#issuecomment-1094167025)
* @default true
*/
- register?: boolean;
+ cacheStartUrl?: boolean;
+ /**
+ * The output directory of the custom worker.
+ * @default dest
+ */
+ customWorkerDest?: string;
+ // NEXT-PWA-TODO(major): remove this option
+ /**
+ * @deprecated renamed to `customWorkerSrc`, to be removed next major version.
+ */
+ customWorkerDir?: string;
+ /**
+ * The custom worker's output filename prefix.
+ * @default "worker"
+ */
+ customWorkerPrefix?: string;
+ /**
+ * Change the directory in which `next-pwa` looks for a custom worker
+ * implementation to import into the service worker. Relative to the root or `src`
+ * directory.
+ * @default "worker"
+ */
+ customWorkerSrc?: string;
// NEXT-PWA-TODO(major): change this option's default to `"public"`
/**
* Set the output directory for service worker. Relative to Next.js's root
@@ -66,16 +73,10 @@ export interface PluginOptions {
*/
dest?: string;
/**
- * The service worker's output filename.
- * @default "/sw.js"
- */
- sw?: string;
- /**
- * Turn on caching for the start URL. [Discussion on use cases for this
- * option](https://github.com/shadowwalker/next-pwa/pull/296#issuecomment-1094167025)
- * @default true
+ * Whether `next-pwa` should be disabled.
+ * @default false
*/
- cacheStartUrl?: boolean;
+ disable?: boolean;
/**
* If your start URL returns different HTML documents under different states
* (such as logged in and not logged in), this should be set to true if you
@@ -93,30 +94,12 @@ export interface PluginOptions {
*/
dynamicStartUrlRedirect?: string;
/**
- * An array of glob pattern strings to exclude files in the public folder from
- * being precached. By default, this plugin excludes `public/noprecache`.
- * Note that you have to add `!` before each glob pattern for it to work.
- * @example
- * ```ts
- * ["!img/super-large-image.jpg", "!fonts/not-used-fonts.otf"];
- * ```
- */
- publicExcludes?: string[];
- /**
- * One or more specifiers used to exclude assets from the precache manifest.
- * This is interpreted following the same rules as Webpack's standard `exclude`
- * option. Relative to `.next/static` or your custom build folder. Defaults to
- * [].
- * @example
- * ```ts
- * [/chunks\/images\/.*$/];
- * ```
- * @default
- * ```ts
- * [];
- * ```
+ * Extend the default `runtimeCaching` array when `runtimeCaching` is specified.
+ * Entries having the same `cacheName` as any entry in the default `runtimeCaching`
+ * array will override it.
+ * @default false
*/
- buildExcludes?: GenerateSWConfig["exclude"];
+ extendDefaultRuntimeCaching?: boolean;
/**
* Configure routes to be precached so that they can be used as a fallback when
* fetching a resource from both the cache and the network fails. If you just need
@@ -124,77 +107,105 @@ export interface PluginOptions {
*/
fallbacks?: FallbackRoutes;
/**
- * Enable additional route caching when users navigate through pages with
- * `next/link`. This improves user experience in some cases but it
- * also adds some overhead because of additional network calls.
- * @default false
- */
- cacheOnFrontEndNav?: boolean;
- /**
- * Cache every `` and `` on frontend navigation.
- * Requires `cacheOnFrontEndNav` to be enabled.
- * @default false
+ * An array of glob pattern strings to exclude files in the public folder from
+ * being precached. By default, this plugin excludes `public/noprecache`.
+ * Note that you have to add `!` before each glob pattern for it to work.
+ * @example
+ * ```ts
+ * ["!img/super-large-image.jpg", "!fonts/not-used-fonts.otf"];
+ * ```
*/
- aggressiveFrontEndNavCaching?: boolean;
+ publicExcludes?: string[];
/**
* URL scope for PWA. Set to `/foo/` so that paths under `/foo/` are PWA while others
* are not.
* @default nextConfig.basePath
*/
scope?: string;
- // NEXT-PWA-TODO(major): remove this option
- /**
- * @deprecated renamed to `customWorkerSrc`, to be removed next major version.
- */
- customWorkerDir?: string;
/**
- * Change the directory in which `next-pwa` looks for a custom worker
- * implementation to import into the service worker. Relative to the root or `src`
- * directory.
- * @default "worker"
+ * The service worker's output filename.
+ * @default "/sw.js"
*/
- customWorkerSrc?: string;
+ sw?: string;
/**
- * The output directory of the custom worker.
- * @default dest
+ * Use [`swc`](https://swc.rs) to minify the custom worker, the fallback worker, and more.
+ * @default nextConfig.swcMinify
*/
- customWorkerDest?: string;
+ swcMinify?: boolean;
/**
- * The custom worker's output filename prefix.
- * @default "worker"
+ * Allow this plugin to automatically register the service worker for you. Set
+ * this to `false` if you want to register the service worker yourself, which
+ * can be done by running `window.workbox.register()` in
+ * `componentDidMount` or `useEffect`.
+ * @example
+ * ```tsx
+ * // app/register-pwa.tsx
+ * "use client";
+ * import { useEffect } from "react";
+ * import type { Workbox } from "workbox-window";
+ *
+ * declare global {
+ * interface Window {
+ * workbox: Workbox;
+ * }
+ * }
+ *
+ * export default function RegisterPWA() {
+ * useEffect(() => {
+ * if ("serviceWorker" in navigator && window.workbox !== undefined) {
+ * window.workbox.register();
+ * }
+ * }, []);
+ * return <>>;
+ * }
+ *
+ * // app/layout.tsx
+ * import RegisterPWA from "./register-pwa";
+ *
+ * export default function RootLayout({
+ * children,
+ * }: {
+ * children: React.ReactNode;
+ * }) {
+ * return (
+ *
+ *
+ *
+ * {children}
+ *
+ *
+ * );
+ * }
+ * ```
+ * @default true
*/
- customWorkerPrefix?: string;
+ register?: boolean;
/**
* Reload the app when it has gone back online.
* @default true
*/
reloadOnOnline?: boolean;
+ /**
+ * Watch certain workers for file changes in development mode. This currently includes the
+ * custom worker.
+ * @default false
+ */
+ watchWorkersInDev?: boolean;
/**
* Pass options to `workbox-webpack-plugin`. This one relies on
* `workbox-webpack-plugin`'s own JSDoc, so some information may not be
* exactly correct.
*/
workboxOptions?: WorkboxTypes[keyof WorkboxTypes];
- /**
- * Extend the default `runtimeCaching` array when `runtimeCaching` is specified.
- * Entries having the same `cacheName` as any entry in the default `runtimeCaching`
- * array will override it.
- * @default false
- */
- extendDefaultRuntimeCaching?: boolean;
- /**
- * Use [`swc`](https://swc.rs) to minify the custom worker, the fallback worker, and more.
- * @default nextConfig.swcMinify
- */
- swcMinify?: boolean;
- /**
- * Configure supported browsers using Browserslist.
- * @default "chrome >= 56"
- */
- browserslist?: BrowserslistOptions;
}
export interface FallbackRoutes {
+ /**
+ * Fallback route for audios, defaults to none.
+ * @default undefined
+ */
+ audio?: string;
/**
* Fallback route for document (pages).
* @default
@@ -209,23 +220,18 @@ export interface FallbackRoutes {
*/
data?: string;
/**
- * Fallback route for images, defaults to none.
+ * Fallback route for fonts, defaults to none.
* @default undefined
*/
- image?: string;
+ font?: string;
/**
- * Fallback route for audios, defaults to none.
+ * Fallback route for images, defaults to none.
* @default undefined
*/
- audio?: string;
+ image?: string;
/**
* Fallback route for videos, defaults to none.
* @default undefined
*/
video?: string;
- /**
- * Fallback route for fonts, defaults to none.
- * @default undefined
- */
- font?: string;
}
diff --git a/packages/next-pwa/src/webpack-builders/build-custom-worker.ts b/packages/next-pwa/src/webpack-builders/build-custom-worker.ts
index 18b8634f..e6b21a22 100644
--- a/packages/next-pwa/src/webpack-builders/build-custom-worker.ts
+++ b/packages/next-pwa/src/webpack-builders/build-custom-worker.ts
@@ -13,7 +13,7 @@ import webpack from "webpack";
import { getContentHash } from "../utils.js";
import { defaultSwcRc } from "./.swcrc.js";
-import { NextPWAContext } from "./context.js";
+import { nextPWAContext } from "./context.js";
import { getSharedWebpackConfig } from "./utils.js";
export const buildCustomWorker = ({
@@ -77,6 +77,9 @@ export const buildCustomWorker = ({
);
}
+ // We'd like to use Webpack's `[hash]`, but we can't determine that hash without
+ // Promise (Next doesn't allow Promise in webpack(config, context), but even if we
+ // use Promise we will block the build until our stuff is done)
const name = `${customWorkerPrefix}-${getContentHash(
customWorkerEntry,
isDev
@@ -86,11 +89,12 @@ export const buildCustomWorker = ({
`Building custom worker to ${path.join(customWorkerDest, name)}...`
);
- webpack({
+ const webpackConfig: Configuration = {
...getSharedWebpackConfig({
swcRc,
}),
- mode: NextPWAContext.shouldMinify ? "production" : "development",
+ watch: isDev && nextPWAContext.devWatchWorkers,
+ mode: nextPWAContext.shouldMinify ? "production" : "development",
target: "webworker",
entry: {
main: customWorkerEntry,
@@ -109,11 +113,23 @@ export const buildCustomWorker = ({
}),
...plugins,
],
- }).run((error, status) => {
+ };
+
+ webpack(webpackConfig, (error, status) => {
if (error || status?.hasErrors()) {
- logger.error("Failed to build custom worker.");
- logger.error(status?.toString({ colors: true }));
- process.exit(-1);
+ logger.error("Failed to compile the custom worker.");
+ logger.error(
+ status?.toString({ colors: true }) ?? error?.message ?? "Unknown error"
+ );
+ if (!isDev) {
+ process.exit(-1);
+ }
+ } else {
+ logger.event(
+ `Compiled the custom worker successfully! (${
+ status?.compilation.modules.size ?? 0
+ } modules)`
+ );
}
});
diff --git a/packages/next-pwa/src/webpack-builders/build-fallback-worker.ts b/packages/next-pwa/src/webpack-builders/build-fallback-worker.ts
index 2c83fc72..1f1ae64f 100644
--- a/packages/next-pwa/src/webpack-builders/build-fallback-worker.ts
+++ b/packages/next-pwa/src/webpack-builders/build-fallback-worker.ts
@@ -7,7 +7,7 @@ import webpack from "webpack";
import type { FallbackRoutes } from "../types.js";
import { getContentHash } from "../utils.js";
-import { NextPWAContext } from "./context.js";
+import { nextPWAContext } from "./context.js";
import { getFallbackEnvs } from "./get-fallback-envs.js";
import { getSharedWebpackConfig } from "./utils.js";
@@ -45,11 +45,14 @@ export const buildFallbackWorker = ({
const fallbackJs = path.join(__dirname, `fallback.js`);
+ // We'd like to use Webpack's `[hash]`, but we can't determine that hash without
+ // Promise (Next doesn't allow Promise in webpack(config, context), but even if we
+ // use Promise we will block the build until our stuff is done)
const name = `fallback-${getContentHash(fallbackJs, isDev)}.js`;
webpack({
...getSharedWebpackConfig({}),
- mode: NextPWAContext.shouldMinify ? "production" : "development",
+ mode: nextPWAContext.shouldMinify ? "production" : "development",
target: "webworker",
entry: {
main: fallbackJs,
@@ -70,8 +73,10 @@ export const buildFallbackWorker = ({
],
}).run((error, status) => {
if (error || status?.hasErrors()) {
- logger.error("Failed to build fallback worker.");
- logger.error(status?.toString({ colors: true }));
+ logger.error("Failed to build the fallback worker.");
+ logger.error(
+ status?.toString({ colors: true }) ?? error?.message ?? "Unknown error"
+ );
process.exit(-1);
}
});
diff --git a/packages/next-pwa/src/webpack-builders/build-sw-entry-worker.ts b/packages/next-pwa/src/webpack-builders/build-sw-entry-worker.ts
index 913e6cce..b9a4164a 100644
--- a/packages/next-pwa/src/webpack-builders/build-sw-entry-worker.ts
+++ b/packages/next-pwa/src/webpack-builders/build-sw-entry-worker.ts
@@ -6,7 +6,7 @@ import { CleanWebpackPlugin } from "clean-webpack-plugin";
import webpack from "webpack";
import { getContentHash } from "../utils.js";
-import { NextPWAContext } from "./context.js";
+import { nextPWAContext } from "./context.js";
import { getSharedWebpackConfig } from "./utils.js";
const __dirname = fileURLToPath(new URL(".", import.meta.url));
@@ -28,11 +28,14 @@ export const buildSWEntryWorker = ({
const swEntryWorkerEntry = path.join(__dirname, `sw-entry-worker.js`);
+ // We'd like to use Webpack's `[hash]`, but we can't determine that hash without
+ // Promise (Next doesn't allow Promise in webpack(config, context), but even if we
+ // use Promise we will block the build until our stuff is done)
const name = `swe-worker-${getContentHash(swEntryWorkerEntry, isDev)}.js`;
webpack({
...getSharedWebpackConfig({}),
- mode: NextPWAContext.shouldMinify ? "production" : "development",
+ mode: nextPWAContext.shouldMinify ? "production" : "development",
target: "webworker",
entry: {
main: swEntryWorkerEntry,
@@ -53,7 +56,9 @@ export const buildSWEntryWorker = ({
}).run((error, status) => {
if (error || status?.hasErrors()) {
logger.error("Failed to build the service worker's sub-worker.");
- logger.error(status?.toString({ colors: true }));
+ logger.error(
+ status?.toString({ colors: true }) ?? error?.message ?? "Unknown error"
+ );
process.exit(-1);
}
});
diff --git a/packages/next-pwa/src/webpack-builders/context.ts b/packages/next-pwa/src/webpack-builders/context.ts
index b2224bdf..b0f435b3 100644
--- a/packages/next-pwa/src/webpack-builders/context.ts
+++ b/packages/next-pwa/src/webpack-builders/context.ts
@@ -15,27 +15,32 @@ interface NextPWAContext {
shouldMinify: boolean | undefined;
useSwcMinify: boolean | undefined;
browserslist: BrowserslistOptions | undefined;
+ devWatchWorkers: boolean | undefined;
}
-export const NextPWAContext: NextPWAContext = {
+export const nextPWAContext: NextPWAContext = {
shouldMinify: resolveContextEnv(process.env.NEXT_PWA_MINIFY, convertBoolean),
useSwcMinify: resolveContextEnv(
process.env.NEXT_PWA_SWC_MINIFY,
convertBoolean
),
browserslist: undefined,
+ devWatchWorkers: resolveContextEnv(
+ process.env.NEXT_PWA_DEV_WATCH,
+ convertBoolean
+ ),
};
/**
- * Set default value for a key in `NextPWAContext`.
- * @param key The key in `NextPWAContext`
+ * Set default value for a key in `nextPWAContext`.
+ * @param key The key in `nextPWAContext`
* @param value The value
*/
-export const setDefaultContext = (
+export const setDefaultContext = (
key: T,
- value: (typeof NextPWAContext)[T]
+ value: NextPWAContext[T]
) => {
- if (NextPWAContext[key] === undefined || NextPWAContext[key] === null) {
- NextPWAContext[key] = value;
+ if (nextPWAContext[key] === undefined || nextPWAContext[key] === null) {
+ nextPWAContext[key] = value;
}
};
diff --git a/packages/next-pwa/src/webpack-builders/utils.ts b/packages/next-pwa/src/webpack-builders/utils.ts
index df342ec3..5a60ed81 100644
--- a/packages/next-pwa/src/webpack-builders/utils.ts
+++ b/packages/next-pwa/src/webpack-builders/utils.ts
@@ -9,7 +9,7 @@ import type { Configuration } from "webpack";
import { assertValue } from "../utils.js";
import { defaultSwcRc } from "./.swcrc.js";
-import { NextPWAContext } from "./context.js";
+import { nextPWAContext } from "./context.js";
const __dirname = fileURLToPath(new URL(".", import.meta.url));
@@ -32,7 +32,7 @@ const resolveTerserOptions = (): MinimizerOptions & {
ascii_only: true,
},
resolveSwc,
- useSwcMinify: NextPWAContext.useSwcMinify,
+ useSwcMinify: nextPWAContext.useSwcMinify,
});
interface SharedWebpackConfigOptions {
@@ -42,7 +42,7 @@ interface SharedWebpackConfigOptions {
export const getSharedWebpackConfig = ({
swcRc = defaultSwcRc,
}: SharedWebpackConfigOptions): Configuration => {
- const optimization = NextPWAContext.shouldMinify && {
+ const optimization = nextPWAContext.shouldMinify && {
minimize: true,
minimizer: [
new TerserPlugin({
@@ -52,13 +52,13 @@ export const getSharedWebpackConfig = ({
],
};
assertValue(
- NextPWAContext.browserslist !== undefined,
+ nextPWAContext.browserslist !== undefined,
"Browserslist config is not defined. This is most likely a bug."
);
if (!swcRc.env) {
swcRc.env = {};
}
- swcRc.env.targets = NextPWAContext.browserslist;
+ swcRc.env.targets = nextPWAContext.browserslist;
return {
resolve: {
extensions: [".js", ".ts"],