next-pwa不工作,生产中没有错误

iovurdzv  于 2023-03-18  发布在  PWA
关注(0)|答案(2)|浏览(248)

回购协议是开源的

// next.config.js
const withPWA = require("next-pwa");

module.exports = withPWA({
  pwa: {
    dest: "public",
    sw: '/sw.js'
  },
});

_document.js
_app.js

现场

https://time-stamp.vercel.app
我已检查PWA是否正在处理上述URL或未使用

function isPwa() {
    return ["fullscreen", "standalone", "minimal-ui"].some(
        (displayMode) => window.matchMedia('(display-mode: ' + displayMode + ')').matches
    );
}
isPwa() // false
// https://stackoverflow.com/questions/41742390/javascript-to-check-if-pwa-or-mobile-web
92dk7w1h

92dk7w1h1#

您可能需要像这样使用next-pwa包:

const withPWA = require("next-pwa");
const runtimeCaching = require("next-pwa/cache");

module.exports = withPWA({
  pwa: {
    dest: "public",
    runtimeCaching,
    disable: process.env.NODE_ENV === "development",
  }
});
vql8enpb

vql8enpb2#

更新next-pwa并遵循https://stackoverflow.com/questions/73585089/build-error-when-compiling-next-js-app-using-next-pwa中的步骤对我很有效

相关问题