首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >next-pwa sw.js冗余且不工作于Vercel

next-pwa sw.js冗余且不工作于Vercel
EN

Stack Overflow用户
提问于 2022-06-05 04:59:13
回答 1查看 1.2K关注 0票数 1

我正在开发运行next-pwa的NextJS应用程序,但只在本地环境中工作。但是当我部署到vercel时,sw.js似乎是多余的。我花了这么多时间在这件事上,但还是觉得被困住了。

这是我的next.config.js

代码语言:javascript
复制
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

代码语言:javascript
复制
{
  "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/30692https://github.com/shadowwalker/next-pwa/issues/295

我还遵循了这个回购程序的基本配置:https://github.com/shadowwalker/next-pwa/tree/master/examples/minimal

我也关掉了阻断剂

但是似乎没有什么是可行的,而且sw.js总是多余的

有人能帮忙吗,我做错什么了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-05 12:48:53

我找到了这个问题的答案。

因此,为了使服务工作者工作,我需要在生产构建( npx next build )上构建服务工作者。

构建完成后,我将删除.gitignore上的服务工作人员,使其部署到存储库中。

然后是大麻..。下一个-pwa有效。尽管如此,它需要10分钟才能使服务人员获得成功。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72504909

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档