Skip to content

Commit

Permalink
fix: we should add cli config correctly (#5871)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiveMe-A-Name authored Jun 25, 2024
1 parent 8677d06 commit c5644c9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .changeset/many-laws-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/prod-server': patch
'@modern-js/server': patch
---

fix: we should add cli config correctly
fix: 我们应该正确的添加 cli 配置
5 changes: 4 additions & 1 deletion packages/server/prod-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion packages/server/prod-server/src/netlify.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
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';

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<BaseEnv>(options);

await loadServerEnv(options);
await applyPlugins(server, options);
await server.init();
Expand Down
9 changes: 5 additions & 4 deletions packages/server/server/src/createDevServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ export const createDevServer = async <O extends ServerBaseOptions>(

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,
Expand Down

0 comments on commit c5644c9

Please sign in to comment.