next.js包分析器未创建查看包的页面

我正在尝试通过使用https://www.npmjs.com/package/@next/bundle-analyzer

来减小网站的捆绑包大小

此刻,当我运行displaying 0 elements will set new viewModel displaying 3 elements did set new viewModel View now has 3 elements

npm analyze

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

这是我的"analyze": "cross-env ANALYZE=true next build",

next.config.js

使用此nextjs-analyze-app-bundle tutorial

出了什么问题?

wwz1989 回答:next.js包分析器未创建查看包的页面

看起来这已经被回答了 on Vercel's issues board。在此处复制他们的解决方案:

这些插件是增强配置对象的功能,所以 您必须将它们包装起来,而不是将它们作为参数提供:

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,}));
,

在我这样做之前,

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

module.exports = 
  {
    env: {
      BASE_URL: process.env.BASE_URL,future: {
      webpack5: true,reactStrictMode: true,}

不确定,但我认为你应该只需要一个 module.exports 所以我把我的其他东西像这样包裹在 withBundleAnalyzer

module.exports = withBundleAnalyzer(
  withPWA({
    pwa: {
      dest: 'public',}),{
    env: {
      BASE_URL: process.env.BASE_URL,}
)
本文链接:https://www.f2er.com/1250865.html

大家都在问