【问题标题】:Error in NextJs compilation using next-pwa - web loader使用 next-pwa 编译 NextJs 时出错 - web loader
【发布时间】:2020-06-21 15:02:23
【问题描述】:

我的 nextJS 应用程序运行良好,但我想通过将其转换为 PWA 来进一步改进它。

我已经为此安装了 Next-pwa 包和构建应用程序,但我在浏览器中出现错误。

这是错误:

我按照以下教程进行操作 => tuto link

我是使用网络工作者的新手。我想我需要为图像设置一个解决方案,但我不知道该怎么做。

谢谢你:)

【问题讨论】:

  • 你能显示你的 next.config.js 吗?
  • 嗨,多亏了你,我找到了解决它的方法。我使用了 next-compose 插件,现在它可以工作了。
  • 很高兴听到这个消息。

标签: progressive-web-apps next.js web-worker


【解决方案1】:

解决问题的配置:

// next.config.js
const withImages = require('next-images');
const withPWA = require('next-pwa');
const withPlugins = require('next-compose-plugins');

module.exports = withPlugins([
    [withPWA, {
    pwa: {
    dest: 'public',
    runtimeCaching: [
        {
        urlPattern: /.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
        handler: 'NetworkFirst',
        options: {
        cacheName: 'static-font-assets',
        expiration: {
        maxEntries: 4,
        maxAgeSeconds: 7 * 24 * 60 * 60 // 7 days
        }
        }
        },
        {
        urlPattern: /.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
        handler: 'NetworkFirst',
        options: {
        cacheName: 'static-image-assets',
        expiration: {
        maxEntries: 64,
        maxAgeSeconds: 24 * 60 * 60 // 24 hours
        }
        }
        },
        {
        urlPattern: /.(?:js)$/i,
        handler: 'NetworkFirst',
        options: {
        cacheName: 'static-js-assets',
        expiration: {
        maxEntries: 16,
        maxAgeSeconds: 24 * 60 * 60 // 24 hours
        }
        }
        },
        {
        urlPattern: /.(?:css|less)$/i,
        handler: 'NetworkFirst',
        options: {
        cacheName: 'static-style-assets',
        expiration: {
        maxEntries: 16,
        maxAgeSeconds: 24 * 60 * 60 // 24 hours
        }
        }
        },
        {
        urlPattern: /.(?:json|xml|csv)$/i,
        handler: 'NetworkFirst',
        options: {
        cacheName: 'static-data-assets',
        expiration: {
        maxEntries: 16,
        maxAgeSeconds: 24 * 60 * 60 // 24 hours
        }
        }
        },
        {
        urlPattern: /.*/i,
        handler: 'NetworkFirst',
        options: {
        cacheName: 'others',
        expiration: {
        maxEntries: 16,
        maxAgeSeconds: 24 * 60 * 60 // 24 hours
        }
        }
        }
        ]
        },
    }],
    [withImages],
    ]);

【讨论】:

  • runtimeCaching 不是必需的,withPWA 必须位于配置的末尾。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-18
  • 2017-03-13
  • 2020-06-07
  • 2017-07-14
  • 2017-03-03
  • 2019-12-01
相关资源
最近更新 更多