Skip to content

Commit

Permalink
feat: export PreviewOptions type and correct doc (#3645)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Oct 7, 2024
1 parent f75b1e5 commit 07948bb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/createRsbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
Falsy,
InternalContext,
PluginManager,
PreviewServerOptions,
PreviewOptions,
ResolvedCreateRsbuildOptions,
RsbuildInstance,
RsbuildPlugin,
Expand Down Expand Up @@ -140,7 +140,7 @@ export async function createRsbuild(
setCssExtractPlugin,
});

const preview = async (options?: PreviewServerOptions) => {
const preview = async (options?: PreviewOptions) => {
if (!getNodeEnv()) {
setNodeEnv('production');
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export type {
Polyfill,
PostCSSLoaderOptions,
PostCSSPlugin,
PreviewOptions,
PreconnectOption,
ProxyConfig,
ProxyOptions,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/server/prodServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { logger } from '../logger';
import type {
InternalContext,
NormalizedConfig,
PreviewServerOptions,
PreviewOptions,
RequestHandler,
ServerConfig,
} from '../types';
Expand Down Expand Up @@ -152,7 +152,7 @@ export class RsbuildProdServer {
export async function startProdServer(
context: InternalContext,
config: NormalizedConfig,
{ getPortSilently }: PreviewServerOptions = {},
{ getPortSilently }: PreviewOptions = {},
): Promise<StartServerResult> {
const { port, host, https, portTip } = await getServerConfig({
config,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/types/rsbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type CreateDevServerOptions = StartDevServerOptions & {
runCompile?: boolean;
};

export type PreviewServerOptions = {
export type PreviewOptions = {
/**
* Whether to get port silently
* @default false
Expand Down Expand Up @@ -148,7 +148,7 @@ export type RsbuildInstance = {
isPluginExists: PluginManager['isPluginExists'];

build: ProviderInstance['build'];
preview: (options?: PreviewServerOptions) => Promise<StartServerResult>;
preview: (options?: PreviewOptions) => Promise<StartServerResult>;
initConfigs: ProviderInstance['initConfigs'];
inspectConfig: ProviderInstance['inspectConfig'];
createCompiler: ProviderInstance['createCompiler'];
Expand Down
16 changes: 13 additions & 3 deletions website/docs/en/api/javascript-api/instance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -412,18 +412,28 @@ rsbuildServer.connectWebSocket({ server: httpServer });

## rsbuild.preview

Start a server to preview the production build locally. This method should be executed after `rsbuild.build`.
Start a server to preview the production build locally. This method should be executed after [rsbuild.build](#rsbuildbuild).

- **Type:**

```ts
type PreviewOptions = {
/**
* Whether to get port silently
* @default false
*/
getPortSilently?: boolean;
};

type StartServerResult = {
urls: string[];
port: number;
server: Server;
server: {
close: () => Promise<void>;
};
};

function server(): Promise<StartServerResult>;
function preview(options?: PreviewOptions): Promise<StartServerResult>;
```

- **Example:**
Expand Down
16 changes: 13 additions & 3 deletions website/docs/zh/api/javascript-api/instance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -433,18 +433,28 @@ rsbuildServer.connectWebSocket({ server: httpServer });

## rsbuild.preview

在本地启动 Server 来预览生产模式构建的产物,需要在 `rsbuild.build` 方法之后执行。
在本地启动 server 来预览生产模式构建的产物,需要在 [rsbuild.build](#rsbuildbuild) 方法之后执行。

- **类型:**

```ts
type PreviewOptions = {
/**
* Whether to get port silently
* @default false
*/
getPortSilently?: boolean;
};

type StartServerResult = {
urls: string[];
port: number;
server: Server;
server: {
close: () => Promise<void>;
};
};

function server(): Promise<StartServerResult>;
function preview(options?: PreviewOptions): Promise<StartServerResult>;
```

- **示例:**
Expand Down

0 comments on commit 07948bb

Please sign in to comment.