Yuki Takei 3 лет назад
Родитель
Сommit
65d1e531c8
2 измененных файлов с 50 добавлено и 38 удалено
  1. 49 37
      packages/app/next.config.js
  2. 1 1
      packages/app/package.json

+ 49 - 37
packages/app/next.config.js

@@ -9,42 +9,10 @@ const eazyLogger = require('eazy-logger');
 const { withSuperjson } = require('next-superjson');
 
 const { i18n, localePath } = require('./src/next-i18next.config');
-const { listScopedPackages, listPrefixedPackages } = require('./src/utils/next.config.utils');
-
-
-// setup logger
-const logger = eazyLogger.Logger({
-  prefix: '[{green:next.config.js}] ',
-  useLevelPrefixes: false,
-});
-
-
-const setupWithTM = () => {
-  // define transpiled packages for '@growi/*'
-  const packages = [
-    ...listScopedPackages(['@growi'], { ignorePackageNames: ['@growi/app'] }),
-    // listing ESM packages until experimental.esmExternals works correctly to avoid ERR_REQUIRE_ESM
-    'react-markdown',
-    'unified',
-    'comma-separated-tokens',
-    'decode-named-character-reference',
-    'html-void-elements',
-    'property-information',
-    'space-separated-tokens',
-    'trim-lines',
-    'web-namespaces',
-    'vfile',
-    'zwitch',
-    'emoticon',
-    ...listPrefixedPackages(['remark-', 'rehype-', 'hast-', 'mdast-', 'micromark-', 'micromark-', 'unist-']),
-  ];
-
-  logger.info('{bold:Listing scoped packages for transpiling:}');
-  logger.unprefixed('info', `{grey:${JSON.stringify(packages, null, 2)}}`);
-
-  return require('next-transpile-modules')(packages);
-};
-const withTM = setupWithTM();
+
+
+const isProduction = process.env.NODE_ENV === 'production';
+let isServer = true;
 
 
 // define additional entries
@@ -69,9 +37,11 @@ const nextConfig = {
 
   /** @param config {import('next').NextConfig} */
   webpack(config, options) {
+    isServer = options.isServer;
+
     // Avoid "Module not found: Can't resolve 'fs'"
     // See: https://stackoverflow.com/a/68511591
-    if (!options.isServer) {
+    if (!isServer) {
       config.resolve.fallback.fs = false;
     }
 
@@ -105,4 +75,46 @@ const nextConfig = {
 
 };
 
+
+const passThrough = nextConfig => nextConfig;
+let withTM = passThrough;
+
+if (!isProduction || !isServer) {
+  const { listScopedPackages, listPrefixedPackages } = require('./src/utils/next.config.utils');
+
+  // setup logger
+  const logger = eazyLogger.Logger({
+    prefix: '[{green:next.config.js}] ',
+    useLevelPrefixes: false,
+  });
+
+  const setupWithTM = () => {
+    // define transpiled packages for '@growi/*'
+    const packages = [
+      ...listScopedPackages(['@growi'], { ignorePackageNames: ['@growi/app'] }),
+      // listing ESM packages until experimental.esmExternals works correctly to avoid ERR_REQUIRE_ESM
+      'react-markdown',
+      'unified',
+      'comma-separated-tokens',
+      'decode-named-character-reference',
+      'html-void-elements',
+      'property-information',
+      'space-separated-tokens',
+      'trim-lines',
+      'web-namespaces',
+      'vfile',
+      'zwitch',
+      'emoticon',
+      ...listPrefixedPackages(['remark-', 'rehype-', 'hast-', 'mdast-', 'micromark-', 'micromark-', 'unist-']),
+    ];
+
+    logger.info('{bold:Listing scoped packages for transpiling:}');
+    logger.unprefixed('info', `{grey:${JSON.stringify(packages, null, 2)}}`);
+
+    return require('next-transpile-modules')(packages);
+  };
+
+  withTM = setupWithTM();
+}
+
 module.exports = withSuperjson()(withTM(nextConfig));

+ 1 - 1
packages/app/package.json

@@ -9,9 +9,9 @@
     "build:client": "yarn next build",
     "prebuild:client": "tsc -p tsconfig.build.next.config.json",
     "build:server": "yarn cross-env NODE_ENV=production tsc -p tsconfig.build.server.json && tsc-alias -p tsconfig.build.server.json",
+    "postbuild:server": "npx -y shx mv transpiled/src dist && npx -y shx cp -r transpiled/config/* config && npx -y shx cp -r src/server/views dist/server/ && npx -y shx rm -rf transpiled",
     "clean": "npx -y shx rm -rf dist transpiled",
     "prebuild": "yarn cross-env NODE_ENV=production run-p clean resources:*",
-    "postbuild": "npx -y shx mv transpiled/src dist && npx -y shx cp -r transpiled/config/* config && npx -y shx cp -r src/server/views dist/server/ && npx -y shx rm -rf transpiled",
     "server": "yarn cross-env NODE_ENV=production node -r dotenv-flow/config dist/server/app.js",
     "server:ci": "yarn server --ci",
     "preserver": "yarn cross-env NODE_ENV=production yarn migrate",