Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/core/src/types/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,29 @@ export type RsbuildContext = {
distPath: string;
/** Absolute path of cache files. */
cachePath: string;
/** Info of dev server */
/**
* Dev server information when running in dev mode.
* Available after the dev server has been created.
*
* @example
* ```ts
* import { createRsbuild } from '@rsbuild/core';
*
* async function main() {
* const rsbuild = createRsbuild({
* // ...
* });
* await rsbuild.startDevServer();
* console.log(rsbuild.context.devServer); // { hostname: 'localhost', port: 3000, https: false }
* }
* ```
*/
devServer?: {
/** The hostname the server is running on. */
hostname: string;
/** The port number the server is listening on. */
port: number;
/** Whether the server is using HTTPS protocol. */
https: boolean;
};
/**
Expand Down
18 changes: 17 additions & 1 deletion website/docs/en/api/javascript-api/instance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,33 @@ Here are some tools based on Rsbuild that have already set the `callerName` valu

### context.devServer

Dev server information, including the current dev server hostname and port number.
Dev server information when running in dev mode. Available after the dev server has been created.

- **Type:**

```ts
type DevServer = {
hostname: string;
port: number;
https: boolean;
};
```

- **Example:**

```ts
import { createRsbuild } from '@rsbuild/core';

async function main() {
const rsbuild = createRsbuild({
// ...
});
await rsbuild.startDevServer();

console.log(rsbuild.context.devServer); // { hostname: 'localhost', port: 3000, https: false }
}
```

### context.action

The current action type.
Expand Down
18 changes: 17 additions & 1 deletion website/docs/zh/api/javascript-api/instance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,33 @@ export const myPlugin = {

### context.devServer

Dev server 相关信息,包含了当前 dev server 的 hostname 和端口号
在开发模式下运行时的 dev server 信息。仅在 dev server 创建后可访问

- **类型:**

```ts
type DevServer = {
hostname: string;
port: number;
https: boolean;
};
```

- **示例:**

```ts
import { createRsbuild } from '@rsbuild/core';

async function main() {
const rsbuild = createRsbuild({
// ...
});
await rsbuild.startDevServer();

console.log(rsbuild.context.devServer); // { hostname: 'localhost', port: 3000, https: false }
}
```

### context.action

当前的动作类型。
Expand Down
Loading