Next-Pwa SW.JS多余的
我正在开发运行Next-PWA的NextJS应用程序,但仅在本地环境上工作。但是,当我部署到Vercel时,似乎sw.js
是多余的。我花了很多时间为此,但无论如何都会卡住。
这是我的next.config.js
const { withPlugins } = require("next-compose-plugins");
const withPWA = require("next-pwa");
const runtimeCaching = require("next-pwa/cache");
const nextConfig = {
env: {
API_URL: "https://multikart-graphql-dun.vercel.app/server.js",
},
// if you want to run with local graphQl un-comment below one and comment the above code
// env: {
// API_URL: "http://localhost:4000/graphql",
// },
webpack(config, options) {
config.module.rules.push({
test: /\.svg$/,
issuer: {
test: /\.(js|ts)x?$/,
},
use: ["@svgr/webpack"],
});
return config;
},
};
module.exports = withPlugins(
[
[withImages],
[
withPWA,
{
// reactStrictMode: true,
pwa: {
dest: "public",
sw: "sw.js",
// swSrc: "service-worker.js",
// scope: "/",
// register: true,
// skipWaiting: true,
// buildExcludes: [/middleware-manifest.json$/],
},
},
],
],
[nextConfig]
);
,这是我的subtest.json
{
"short_name": "App",
"name": "App: App",
"start_url": "/",
"display": "standalone",
"theme_color": "#b8d8e6",
"background_color": "#b8d8e6",
"prefer_related_applications": true,
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "/icons/imagedummy192.png",
"type": "image/png",
"sizes": "192x192",
"purpose": "any maskable"
},
{
"src": "/icons/imagedummy512.png",
"type": "image/png",
"sizes": "512x512"
}
]
}
评论了config的其余部分(runtimecaching,skipwaiting,regission)
我 https://github.com/vithub.com/vercel/vercel/next.js/issues/30692 and https://github.com/shadowwalker/next-pwa/next-pwa/issues/sissues/295 < /a>
我还遵循此回购上的基本配置: https:/https:/ /Github.com/shadowwalker/next-pwa/tree/master/examples/minimal
我也关闭了adblocker
,但似乎无效,但sw.js
始终有多余的
人可以帮助,我做错了什么?
I am working on NextJS app that runs next-pwa but only works on local environment. But when I deploy to vercel, it seems that sw.js
is redundant. I spent so many hours on this but feel stuck anyway.
Here's my next.config.js
const { withPlugins } = require("next-compose-plugins");
const withPWA = require("next-pwa");
const runtimeCaching = require("next-pwa/cache");
const nextConfig = {
env: {
API_URL: "https://multikart-graphql-dun.vercel.app/server.js",
},
// if you want to run with local graphQl un-comment below one and comment the above code
// env: {
// API_URL: "http://localhost:4000/graphql",
// },
webpack(config, options) {
config.module.rules.push({
test: /\.svg$/,
issuer: {
test: /\.(js|ts)x?$/,
},
use: ["@svgr/webpack"],
});
return config;
},
};
module.exports = withPlugins(
[
[withImages],
[
withPWA,
{
// reactStrictMode: true,
pwa: {
dest: "public",
sw: "sw.js",
// swSrc: "service-worker.js",
// scope: "/",
// register: true,
// skipWaiting: true,
// buildExcludes: [/middleware-manifest.json$/],
},
},
],
],
[nextConfig]
);
and here's my manifest.json
{
"short_name": "App",
"name": "App: App",
"start_url": "/",
"display": "standalone",
"theme_color": "#b8d8e6",
"background_color": "#b8d8e6",
"prefer_related_applications": true,
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "/icons/imagedummy192.png",
"type": "image/png",
"sizes": "192x192",
"purpose": "any maskable"
},
{
"src": "/icons/imagedummy512.png",
"type": "image/png",
"sizes": "512x512"
}
]
}
I commented the rest of the config (runTimeCaching, skipWaiting, register), since it makes no difference
I have followed https://github.com/vercel/next.js/issues/30692 and https://github.com/shadowwalker/next-pwa/issues/295
I also have followed basic config on this repo: https://github.com/shadowwalker/next-pwa/tree/master/examples/minimal
I also did turn off the adblocker
but nothing seems to work, and sw.js
always redundant
Can anybody help, What did I do wrong? ????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了这个问题的答案。
因此,为了使服务工作者有效,我需要在生产构建时构建服务工作者(
npx Next Build
)。构建完成后,我在
.gitignore
上删除服务工作者,以使其部署到存储库。然后瞧。下一-PWA起作用。虽然,需要10分钟才能建立服务工作者。
I found an answer to the question.
So to make the service worker works, I needed to build the service worker on production build (
npx next build
).After the build complete, I remove the service worker on
.gitignore
to make it deployed to the repository.And then voilaa.. the next-pwa works. Although, it needs 10 minutes for service worker success to build.