Nextjs删除工作箱console.log消息
知道如何在 NextJS 项目中禁用这些 console.log 消息workbox吗?我刚刚开始了一个新的回购,它只是给了我太多我现在不需要的信息
回答
从next-pwa docs,提示部分:
您需要做的就是worker在项目的根目录中创建目录并将index.js文件放入其中:
// To disable all workbox logging during development, you can set self.__WB_DISABLE_DEV_LOGS to true
// https://developers.google.com/web/tools/workbox/guides/configure-workbox#disable_logging
// eslint-disable-next-line no-underscore-dangle,no-restricted-globals
self.__WB_DISABLE_DEV_LOGS = true;
然后重新启动服务器 - 控制台中必须没有日志。
我还发现另一个有用的选项 - 在开发过程中完全禁用 sw。您可以使用disablein 选项来做到这next.config.js一点,例如我的:
const path = require('path');
const withPWA = require('next-pwa');
const runtimeCaching = require('next-pwa/cache');
module.exports = withPWA({
pwa: {
dest: 'public',
scope: '/',
runtimeCaching,
disable: process.env.NODE_ENV === 'development',
},
sassOptions: {
includePaths: [path.join(__dirname, 'assets/jss/vendor')],
},
});
服务器重启后,sw将不再接收更新,但您需要手动删除旧的: