next.js 包分析器不会创建页面来查看包

Mic*_*orn 5 reactjs webpack next.js webpack-bundle-analyzer

我正在尝试使用https://www.npmjs.com/package/@next/bundle-analyzer来减小我网站的包大小

此刻,当我npm analyze

"analyze": "cross-env ANALYZE=true next build",
Run Code Online (Sandbox Code Playgroud)

它不输出具有所需可视化效果的 html 文件。

这是我的 next.config.js

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


const withBundleAnalyzer = require('@next/bundle-analyzer')({
    enabled: process.env.ANALYZE === 'true',
  })

module.exports = withPWA({
  pwa: {
    dest: 'public',
    runtimeCaching,
  },
  poweredByHeader: false,
},
withBundleAnalyzer(),

)
Run Code Online (Sandbox Code Playgroud)

使用这个nextjs-analyze-app-bundle 教程

出了什么问题?

小智 4

看起来Vercel 的问题板上已经回答了这个问题。在这里复制他们的解决方案:

这些插件是增强配置对象的函数,因此您必须包装它们而不是将它们作为参数提供:

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


const withBundleAnalyzer = require('@next/bundle-analyzer')({
    enabled: process.env.ANALYZE === 'true',
});

module.exports = withBundleAnalyzer(withPWA({
    pwa: {
        dest: 'public',
        runtimeCaching,
    },
    poweredByHeader: false,
}));
Run Code Online (Sandbox Code Playgroud)