我正在开发运行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]
);这是我的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"
}
]
}我评论了配置的其余部分(runTimeCaching,skipWaiting,寄存器),因为它没有什么区别。
我跟踪了https://github.com/vercel/next.js/issues/30692和https://github.com/shadowwalker/next-pwa/issues/295
我还遵循了这个回购程序的基本配置:https://github.com/shadowwalker/next-pwa/tree/master/examples/minimal
我也关掉了阻断剂
但是似乎没有什么是可行的,而且sw.js总是多余的
有人能帮忙吗,我做错什么了?
发布于 2022-06-05 12:48:53
我找到了这个问题的答案。
因此,为了使服务工作者工作,我需要在生产构建( npx next build )上构建服务工作者。
构建完成后,我将删除.gitignore上的服务工作人员,使其部署到存储库中。
然后是大麻..。下一个-pwa有效。尽管如此,它需要10分钟才能使服务人员获得成功。
https://stackoverflow.com/questions/72504909
复制相似问题