From c5644c9bb610b86506887d7208206b4e710851fa Mon Sep 17 00:00:00 2001 From: qixuan <58852732+GiveMe-A-Name@users.noreply.github.com> Date: Tue, 25 Jun 2024 14:35:13 +0800 Subject: [PATCH] fix: we should add cli config correctly (#5871) --- .changeset/many-laws-scream.md | 7 +++++++ packages/server/prod-server/src/index.ts | 5 ++++- packages/server/prod-server/src/netlify.ts | 12 +++++++++++- packages/server/server/src/createDevServer.ts | 9 +++++---- 4 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 .changeset/many-laws-scream.md diff --git a/.changeset/many-laws-scream.md b/.changeset/many-laws-scream.md new file mode 100644 index 000000000000..4a6b4c75c824 --- /dev/null +++ b/.changeset/many-laws-scream.md @@ -0,0 +1,7 @@ +--- +'@modern-js/prod-server': patch +'@modern-js/server': patch +--- + +fix: we should add cli config correctly +fix: 我们应该正确的添加 cli 配置 diff --git a/packages/server/prod-server/src/index.ts b/packages/server/prod-server/src/index.ts index f7dc4ad3c2bf..b91225e80dc8 100644 --- a/packages/server/prod-server/src/index.ts +++ b/packages/server/prod-server/src/index.ts @@ -23,7 +23,10 @@ export const createProdServer = async (options: ProdServerOptions) => { const serverBaseOptions = options; - const serverCliConfig = loadServerCliConfig(options.pwd, options.config); + const serverCliConfig = + process.env.NODE_ENV === 'production' + ? loadServerCliConfig(options.pwd, options.config) + : options.config; if (serverCliConfig) { serverBaseOptions.config = serverCliConfig; diff --git a/packages/server/prod-server/src/netlify.ts b/packages/server/prod-server/src/netlify.ts index 889436713074..9d4ffa22a9c2 100644 --- a/packages/server/prod-server/src/netlify.ts +++ b/packages/server/prod-server/src/netlify.ts @@ -1,4 +1,7 @@ -import { loadServerEnv } from '@modern-js/server-core/node'; +import { + loadServerCliConfig, + loadServerEnv, +} from '@modern-js/server-core/node'; import { createServerBase } from '@modern-js/server-core'; import { BaseEnv, ProdServerOptions } from './types'; import { applyPlugins } from './apply'; @@ -6,7 +9,14 @@ import { applyPlugins } from './apply'; export type { ProdServerOptions, BaseEnv } from './types'; export const createNetlifyFunction = async (options: ProdServerOptions) => { + const serverCliConfig = loadServerCliConfig(options.pwd, options.config); + + if (serverCliConfig) { + options.config = serverCliConfig; + } + const server = createServerBase(options); + await loadServerEnv(options); await applyPlugins(server, options); await server.init(); diff --git a/packages/server/server/src/createDevServer.ts b/packages/server/server/src/createDevServer.ts index dddf9d79cb0a..f1f1ea62ae7e 100644 --- a/packages/server/server/src/createDevServer.ts +++ b/packages/server/server/src/createDevServer.ts @@ -20,10 +20,11 @@ export const createDevServer = async ( const distDir = path.resolve(pwd, config.output.path || 'dist'); - const serverConfig = - process.env.NODE_ENV === 'production' - ? loadServerRuntimeConfig(distDir, serverConfigFile, serverConfigPath) - : options.config; + const serverConfig = loadServerRuntimeConfig( + distDir, + serverConfigFile, + serverConfigPath, + ); const prodServerOptions = { ...options,