Skip to content

Commit

Permalink
chore: optimize server options
Browse files Browse the repository at this point in the history
  • Loading branch information
ErKeLost committed Nov 8, 2024
1 parent 1e42476 commit 9a016f8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/docs/config/dev-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface UserServerConfig {
https?: SecureServerOptions;
protocol?: 'http' | 'https';
// http2?: boolean;
hmr?: boolean | UserHmrConfig;
hmr?: boolean | HmrOptions;
proxy?: Record<string, ProxiesOptions>;
strictPort?: boolean;
open?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface UserServerConfig {
protocol?: "http" | "https";
hostname?: string;
// http2?: boolean;
hmr?: boolean | UserHmrConfig;
hmr?: boolean | HmrOptions;
proxy?: Record<string, ProxiesOptions>;
strictPort?: boolean;
open?: boolean;
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ import type { OutputConfig } from '../types/binding.js';
import type {
ConfigEnv,
FarmCliOptions,
HmrOptions,
NormalizedServerConfig,
ResolvedCompilation,
ResolvedUserConfig,
UserConfig,
UserConfigExport,
UserConfigFnObject,
UserHmrConfig,
UserServerConfig
} from './types.js';

Expand Down Expand Up @@ -508,7 +508,7 @@ export async function normalizeUserCompilationConfig(
return resolvedCompilation;
}

export const DEFAULT_HMR_OPTIONS: Required<UserHmrConfig> = {
export const DEFAULT_HMR_OPTIONS: Required<HmrOptions> = {
host: 'localhost',
port:
(process.env.FARM_DEFAULT_HMR_PORT &&
Expand All @@ -517,7 +517,6 @@ export const DEFAULT_HMR_OPTIONS: Required<UserHmrConfig> = {
path: '/__hmr',
overlay: true,
protocol: 'ws',
watchOptions: {},
clientPort: 9000,
timeout: 0,
server: null,
Expand Down
9 changes: 2 additions & 7 deletions packages/core/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface UserServerConfig {
protocol?: 'http' | 'https';
hostname?: { name: string; host: string | undefined };
// http2?: boolean;
hmr?: boolean | UserHmrConfig;
hmr?: boolean | HmrOptions;
proxy?: Record<string, any>;
strictPort?: boolean;
open?: boolean;
Expand All @@ -80,7 +80,7 @@ export interface UserPreviewServerConfig {

export type NormalizedServerConfig = Required<
Omit<UserServerConfig, 'hmr'> & {
hmr?: UserHmrConfig;
hmr?: HmrOptions;
}
>;

Expand All @@ -89,11 +89,6 @@ export interface NormalizedConfig {
serverConfig?: NormalizedServerConfig;
}

export interface UserHmrConfig extends HmrOptions {
watchOptions?: WatchOptions;
overlay?: boolean;
}

type InternalConfig = Config['config'] extends undefined
? object
: Required<Config>['config'];
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/server/hmr-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { stat } from 'node:fs/promises';
import { isAbsolute, relative } from 'node:path';

import type { Resource } from '@farmfe/runtime/src/resource-loader.js';
import { UserHmrConfig } from '../config/index.js';
import { HmrOptions } from '../config/index.js';
import type { JsUpdateResult } from '../types/binding.js';
import { convertErrorMessage } from '../utils/error.js';
import { bold, cyan, green } from '../utils/index.js';
Expand Down Expand Up @@ -181,8 +181,7 @@ export class HmrEngine {
type: 'error',
err: ${errorStr},
overlay: ${
(this.app.resolvedUserConfig.server.hmr as UserHmrConfig)
.overlay
(this.app.resolvedUserConfig.server.hmr as HmrOptions).overlay
}
}
`);
Expand Down

0 comments on commit 9a016f8

Please sign in to comment.