Explorar o código

Merge branch 'dev/7.5.x' into support/optimize-presentation

Yuki Takei hai 2 semanas
pai
achega
bd981f752b
Modificáronse 4 ficheiros con 63 adicións e 64 borrados
  1. 1 0
      apps/app/.gitignore
  2. 5 4
      apps/app/bin/assemble-prod.sh
  3. 56 59
      apps/app/next.config.ts
  4. 1 1
      apps/app/package.json

+ 1 - 0
apps/app/.gitignore

@@ -2,6 +2,7 @@
 /.next/
 /.next/
 /out/
 /out/
 next-env.d.ts
 next-env.d.ts
+next.config.js
 
 
 # test
 # test
 .reg
 .reg

+ 5 - 4
apps/app/bin/assemble-prod.sh

@@ -20,10 +20,11 @@ echo "[3/4] Removing build cache..."
 rm -rf apps/app/.next/cache
 rm -rf apps/app/.next/cache
 echo "[3/4] Done."
 echo "[3/4] Done."
 
 
-# Remove next.config.ts to prevent Next.js from attempting to install TypeScript at server startup,
-# which would corrupt node_modules (e.g. @growi/core).
-echo "[4/4] Removing next.config.ts..."
-rm -f apps/app/next.config.ts
+# Provide a CJS runtime config so the production server can load it without TypeScript.
+# next.config.js takes precedence over next.config.ts in Next.js, so the .ts file
+# is left in place but effectively ignored at runtime.
+echo "[4/4] Installing runtime next.config.js..."
+cp apps/app/next.config.prod.cjs apps/app/next.config.js
 echo "[4/4] Done."
 echo "[4/4] Done."
 
 
 echo "Assembly complete."
 echo "Assembly complete."

+ 56 - 59
apps/app/next.config.ts

@@ -6,7 +6,6 @@
  */
  */
 
 
 import type { NextConfig } from 'next';
 import type { NextConfig } from 'next';
-import { PHASE_PRODUCTION_SERVER } from 'next/constants';
 import path from 'node:path';
 import path from 'node:path';
 
 
 import nextI18nConfig from './config/next-i18next.config';
 import nextI18nConfig from './config/next-i18next.config';
@@ -85,66 +84,64 @@ const optimizePackageImports: string[] = [
   '@growi/ui',
   '@growi/ui',
 ];
 ];
 
 
-export default (phase: string): NextConfig => {
-  /** @type {import('next').NextConfig} */
-  const nextConfig: NextConfig = {
-    reactStrictMode: true,
-    poweredByHeader: false,
-    pageExtensions: ['page.tsx', 'page.ts', 'page.jsx', 'page.js'],
-    i18n,
+// This config is used at build time only (next build / next dev).
+// Production runtime uses next.config.prod.cjs (installed as next.config.js by assemble-prod.sh).
+const nextConfig: NextConfig = {
+  reactStrictMode: true,
+  poweredByHeader: false,
+  pageExtensions: ['page.tsx', 'page.ts', 'page.jsx', 'page.js'],
+  i18n,
 
 
-    serverExternalPackages: [
-      'handsontable', // Legacy v6.2.2 requires @babel/polyfill which is unavailable; client-only via dynamic import
-    ],
+  serverExternalPackages: [
+    'handsontable', // Legacy v6.2.2 requires @babel/polyfill which is unavailable; client-only via dynamic import
+  ],
 
 
-    // for build
-    typescript: {
-      tsconfigPath: 'tsconfig.build.client.json',
-    },
-    transpilePackages:
-      phase !== PHASE_PRODUCTION_SERVER ? getTranspilePackages() : undefined,
-    sassOptions: {
-      loadPaths: [path.resolve(__dirname, 'src')],
-    },
-    experimental: {
-      optimizePackageImports,
-    },
+  // for build
+  typescript: {
+    tsconfigPath: 'tsconfig.build.client.json',
+  },
+  transpilePackages: getTranspilePackages(),
+  sassOptions: {
+    loadPaths: [path.resolve(__dirname, 'src')],
+  },
+  experimental: {
+    optimizePackageImports,
+  },
 
 
-    turbopack: {
-      rules: {
-        // Server-only: auto-wrap getServerSideProps with SuperJSON serialization
-        '*.page.ts': [
-          {
-            condition: { not: 'browser' },
-            loaders: [
-              path.resolve(__dirname, 'src/utils/superjson-ssr-loader.ts'),
-            ],
-            as: '*.ts',
-          },
-        ],
-        '*.page.tsx': [
-          {
-            condition: { not: 'browser' },
-            loaders: [
-              path.resolve(__dirname, 'src/utils/superjson-ssr-loader.ts'),
-            ],
-            as: '*.tsx',
-          },
-        ],
-      },
-      resolveAlias: {
-        // Exclude fs from client bundle
-        fs: { browser: './src/lib/empty-module.ts' },
-        // Exclude server-only packages from client bundle
-        'dtrace-provider': { browser: './src/lib/empty-module.ts' },
-        mongoose: { browser: './src/lib/empty-module.ts' },
-        'i18next-fs-backend': { browser: './src/lib/empty-module.ts' },
-        bunyan: { browser: './src/lib/empty-module.ts' },
-        'bunyan-format': { browser: './src/lib/empty-module.ts' },
-        'core-js': { browser: './src/lib/empty-module.ts' },
-      },
+  turbopack: {
+    rules: {
+      // Server-only: auto-wrap getServerSideProps with SuperJSON serialization
+      '*.page.ts': [
+        {
+          condition: { not: 'browser' },
+          loaders: [
+            path.resolve(__dirname, 'src/utils/superjson-ssr-loader.ts'),
+          ],
+          as: '*.ts',
+        },
+      ],
+      '*.page.tsx': [
+        {
+          condition: { not: 'browser' },
+          loaders: [
+            path.resolve(__dirname, 'src/utils/superjson-ssr-loader.ts'),
+          ],
+          as: '*.tsx',
+        },
+      ],
     },
     },
-  };
-
-  return nextConfig;
+    resolveAlias: {
+      // Exclude fs from client bundle
+      fs: { browser: './src/lib/empty-module.ts' },
+      // Exclude server-only packages from client bundle
+      'dtrace-provider': { browser: './src/lib/empty-module.ts' },
+      mongoose: { browser: './src/lib/empty-module.ts' },
+      'i18next-fs-backend': { browser: './src/lib/empty-module.ts' },
+      bunyan: { browser: './src/lib/empty-module.ts' },
+      'bunyan-format': { browser: './src/lib/empty-module.ts' },
+      'core-js': { browser: './src/lib/empty-module.ts' },
+    },
+  },
 };
 };
+
+export default nextConfig;

+ 1 - 1
apps/app/package.json

@@ -10,7 +10,7 @@
     "build:client": "next build",
     "build:client": "next build",
     "build:server": "cross-env NODE_ENV=production tspc -p tsconfig.build.server.json",
     "build:server": "cross-env NODE_ENV=production tspc -p tsconfig.build.server.json",
     "postbuild:server": "shx echo \"Listing files under transpiled\" && shx ls transpiled && shx rm -rf dist && shx mv transpiled/src dist && shx rm -rf transpiled",
     "postbuild:server": "shx echo \"Listing files under transpiled\" && shx ls transpiled && shx rm -rf dist && shx mv transpiled/src dist && shx rm -rf transpiled",
-    "clean": "shx rm -rf dist transpiled .next",
+    "clean": "shx rm -rf dist transpiled .next next.config.js",
     "server": "cross-env NODE_ENV=production node -r dotenv-flow/config dist/server/app.js",
     "server": "cross-env NODE_ENV=production node -r dotenv-flow/config dist/server/app.js",
     "server:ci": "pnpm run server --ci",
     "server:ci": "pnpm run server --ci",
     "preserver": "cross-env NODE_ENV=production pnpm run migrate",
     "preserver": "cross-env NODE_ENV=production pnpm run migrate",