Skip to content

Commit

Permalink
fix(core): fixed using fallbacks with files in the public directory
Browse files Browse the repository at this point in the history
[bump]
  • Loading branch information
DuCanhGH committed Feb 3, 2024
1 parent db2e02c commit e6ce949
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
7 changes: 7 additions & 0 deletions .changeset/eighty-snails-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@ducanh2912/next-pwa": patch
---

fix(core): fixed using fallbacks with files in the public directory

- Silly mistakes... Sorry for the inconvenience.
49 changes: 25 additions & 24 deletions packages/next-pwa/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,29 @@ export const parseOptions = (
const publicDir = path.resolve(webpackContext.dir, "public");

if (!additionalManifestEntries) {
additionalManifestEntries = fg
.sync(
[
"**/*",
"!workbox-*.js",
"!workbox-*.js.map",
"!worker-*.js",
"!worker-*.js.map",
"!fallback-*.js",
"!fallback-*.js.map",
"!swe-worker-*.js",
"!swe-worker-*.js.map",
`!${sw.replace(/^\/+/, "")}`,
`!${sw.replace(/^\/+/, "")}.map`,
...publicExcludes,
],
{
cwd: publicDir,
},
)
.map((f) => ({
url: path.posix.join(nextConfig.basePath, f),
revision: getFileHash(path.resolve(publicDir, f)),
}));
const publicDirScan = fg.sync(
[
"**/*",
"!workbox-*.js",
"!workbox-*.js.map",
"!worker-*.js",
"!worker-*.js.map",
"!fallback-*.js",
"!fallback-*.js.map",
"!swe-worker-*.js",
"!swe-worker-*.js.map",
`!${sw.replace(/^\/+/, "")}`,
`!${sw.replace(/^\/+/, "")}.map`,
...publicExcludes,
],
{
cwd: publicDir,
},
);
additionalManifestEntries = publicDirScan.map((f) => ({
url: path.posix.join(nextConfig.basePath, f),
revision: getFileHash(path.resolve(publicDir, f)),
}));
}

if (cacheStartUrl) {
Expand Down Expand Up @@ -183,7 +182,9 @@ export const parseOptions = (
const asset = (compilation as any).assetsInfo.get(key);
m.revision = asset ? asset.contenthash || webpackContext.buildId : webpackContext.buildId;
}

m.url = m.url.replace(/\[/g, "%5B").replace(/\]/g, "%5D");

return m;
});
return { manifest, warnings: [] };
Expand Down
4 changes: 1 addition & 3 deletions packages/next-pwa/src/webpack/builders/build-workers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { Configuration } from "webpack";
import type { ManifestEntry } from "workbox-build";

import { NextPwaContext } from "../../context.js";
import { buildCustomWorker } from "./build-custom-worker.js";
import { buildFallbackWorker } from "./build-fallback-worker.js";

export const buildWorkers = (ctx: NextPwaContext) => {
const additionalManifestEntries: ManifestEntry[] = [];
const childCompilationInstances: NonNullable<Configuration["plugins"]> = [];

const customWorker = buildCustomWorker(ctx);
Expand Down Expand Up @@ -36,7 +34,7 @@ export const buildWorkers = (ctx: NextPwaContext) => {
if (
route &&
typeof route !== "boolean" &&
!additionalManifestEntries.find((entry) => typeof entry !== "string" && entry.url.startsWith(route))
!ctx.options.workboxOptions.additionalManifestEntries.find((entry) => typeof entry === "object" && entry.url.startsWith(route))
) {
ctx.options.workboxOptions.additionalManifestEntries.push({
url: route,
Expand Down

0 comments on commit e6ce949

Please sign in to comment.