forked from shadowwalker/next-pwa
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(next-pwa,compatibility): remove
node:
protocol from imports
[bump]
- Loading branch information
Showing
10 changed files
with
184 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@ducanh2912/next-pwa": patch | ||
--- | ||
|
||
fix(next-pwa,compatibility): remove `node:` protocol from imports | ||
|
||
- We currently don't have a clear version requirement for Node.js, and as such we should support as many versions as possible. It seems that only Node.js 16 and later support `node:` protocol imports for CJS, so we remove this protocol by using `@rollup/plugin-alias`. This compatibility patch might be removed in the future though. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import path from "node:path"; | ||
|
||
import type { Asset, Configuration } from "webpack"; | ||
import type { ManifestEntry, ManifestTransform } from "workbox-build"; | ||
import type { GenerateSWConfig } from "workbox-webpack-plugin"; | ||
|
||
import type { SharedWorkboxOptionsKeys } from "./private-types.js"; | ||
import type { PluginOptions } from "./types.js"; | ||
|
||
interface ResolveWorkboxCommonOptions { | ||
dest: string; | ||
sw: string; | ||
dev: boolean; | ||
buildId: string; | ||
buildExcludes: NonNullable<PluginOptions["buildExcludes"]>; | ||
manifestEntries: (string | ManifestEntry)[]; | ||
manifestTransforms: ManifestTransform[]; | ||
modifyURLPrefix: Record<string, string>; | ||
publicPath: NonNullable<Configuration["output"]>["publicPath"]; | ||
} | ||
|
||
export const resolveWorkboxCommon = ({ | ||
dest, | ||
sw, | ||
dev, | ||
buildId, | ||
buildExcludes, | ||
manifestEntries, | ||
manifestTransforms, | ||
modifyURLPrefix, | ||
publicPath, | ||
}: ResolveWorkboxCommonOptions): Pick< | ||
GenerateSWConfig, | ||
SharedWorkboxOptionsKeys | ||
> => ({ | ||
swDest: path.join(dest, sw), | ||
additionalManifestEntries: dev ? [] : manifestEntries, | ||
exclude: [ | ||
...buildExcludes, | ||
({ asset }: { asset: Asset }) => { | ||
if ( | ||
asset.name.startsWith("server/") || | ||
asset.name.match( | ||
/^((app-|^)build-manifest\.json|react-loadable-manifest\.json)$/ | ||
) | ||
) { | ||
return true; | ||
} | ||
if (dev && !asset.name.startsWith("static/runtime/")) { | ||
return true; | ||
} | ||
return false; | ||
}, | ||
], | ||
modifyURLPrefix: { | ||
...modifyURLPrefix, | ||
"/_next/../public/": "/", | ||
}, | ||
manifestTransforms: [ | ||
...manifestTransforms, | ||
async (manifestEntries, compilation) => { | ||
const manifest = manifestEntries.map((m) => { | ||
m.url = m.url.replace("/_next//static/image", "/_next/static/image"); | ||
m.url = m.url.replace("/_next//static/media", "/_next/static/media"); | ||
if (m.revision === null) { | ||
let key = m.url; | ||
if (typeof publicPath === "string" && key.startsWith(publicPath)) { | ||
key = m.url.substring(publicPath.length); | ||
} | ||
const asset = (compilation as any).assetsInfo.get(key); | ||
m.revision = asset ? asset.contenthash || buildId : buildId; | ||
} | ||
m.url = m.url.replace(/\[/g, "%5B").replace(/\]/g, "%5D"); | ||
return m; | ||
}); | ||
return { manifest, warnings: [] }; | ||
}, | ||
], | ||
}); |
Oops, something went wrong.