progressive-web-apps - 使用 next-pwa 编译 NextJs 时出错 - web loader
问题描述
我的 nextJS 应用程序运行良好,但我想通过将其转换为 PWA 来进一步改进它。
我已经为此安装了 Next-pwa 包和构建应用程序,但我在浏览器中有错误。
这是错误:
我按照以下教程=> tuto链接
我是使用网络工作者的新手。我想我需要为图像设置一个解决方案,但我不知道该怎么做。
谢谢你 :)
解决方案
解决问题的配置:
// 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],
]);
推荐阅读
- python - 跨行的 Pandas DataFrame 条件
- c++ - 如何修复 emacs 中的 c++ 缩进?
- javascript - 如何在 React.js 中使用溢出:隐藏以及位置:粘性
- javascript - “autoNumeric.js”在动态创建的表单元素中不起作用
- python - 在 python 中使用 selenium 时出现了一些错误
- r - 使用 ggplot2 从 RgoogleMaps 包中绘制地图
- java - 简单的 Java Http 客户端程序不工作
- api - 如何使用 azure devops api 获取 yaml 管道详细信息
- javascript - 无法在表单中输入输入字段(React.js - Bootstrap)(无法在输入字段中输入任何值)
- java - Android工作室抛出IOException:不允许操作