使用 Nx (16.9.0) 和 NextJS (14.0.4) 构建静态站点时缺少“out”文件夹

问题描述 投票:0回答:1

我目前正在使用 NextJS (14.0.4) 和 Nx (16.9.0) 使用 next.config.js 中的“output: 'export'”参数构建静态站点,详情请参阅NextJS 文档。 这是我正在使用的 next.config.js 文件:

enter image description here

这是我的库版本:

enter image description here enter image description here

构建过程的结果会在名为“dist/apps/myApp/.next”的文件夹中生成静态文件,我能够成功使用这些文件来部署静态网站。 到目前为止没有任何投诉!

但是,我的问题是我是否应该在 NextJS 文档中描述的某处看到“out”文件夹,或者本例中的“out”文件夹是否是“.next”目录。 为了方便参考,这里是 NextJS 文档的屏幕截图,其中提到了“out”文件夹。

enter image description here

我的问题的主要原因是我不确定是否应该直接使用“.next”文件夹中的文件,或者是否应该使用“out”文件夹中的文件。 我在网上阅读的教程似乎主要使用“.next”文件夹中的文件,但我也在一些地方读到不应直接使用这些文件。

如有任何建议,我们将不胜感激!

next.js nrwl-nx
1个回答
0
投票

确保您的环境变量中有

NX_SERVE_STATIC_BUILD_RUNNING=true

为什么?

问题来自“withNx”插件,该插件覆盖了下一个配置的“distDir”:https://github.com/nrwl/nx/blob/master/packages/next/plugins/with-nx。 ts#L198

        nextConfig.distDir =
          nextConfig.distDir && nextConfig.distDir !== '.next'
            ? joinPathFragments(outputDir, nextConfig.distDir)
            : joinPathFragments(outputDir, '.next');

将变量 NX_SERVE_STATIC_BUILD_RUNNING 设置为“true”时,插件会重新覆盖为正确的值:https://github.com/nrwl/nx/blob/master/packages/next/plugins/with-nx.ts# L205

      if (process.env.NX_SERVE_STATIC_BUILD_RUNNING === 'true') {
        nextConfig.output = 'export';
        nextConfig.distDir = 'out';
      }
© www.soinside.com 2019 - 2024. All rights reserved.