File tree Expand file tree Collapse file tree 3 files changed +54
-3
lines changed Expand file tree Collapse file tree 3 files changed +54
-3
lines changed Original file line number Diff line number Diff line change @@ -15,10 +15,29 @@ export type RsbuildContext = {
1515 distPath : string ;
1616 /** Absolute path of cache files. */
1717 cachePath : string ;
18- /** Info of dev server */
18+ /**
19+ * Dev server information when running in dev mode.
20+ * Available after the dev server has been created.
21+ *
22+ * @example
23+ * ```ts
24+ * import { createRsbuild } from '@rsbuild/core';
25+ *
26+ * async function main() {
27+ * const rsbuild = createRsbuild({
28+ * // ...
29+ * });
30+ * await rsbuild.startDevServer();
31+ * console.log(rsbuild.context.devServer); // { hostname: 'localhost', port: 3000, https: false }
32+ * }
33+ * ```
34+ */
1935 devServer ?: {
36+ /** The hostname the server is running on. */
2037 hostname : string ;
38+ /** The port number the server is listening on. */
2139 port : number ;
40+ /** Whether the server is using HTTPS protocol. */
2241 https : boolean ;
2342 } ;
2443 /**
Original file line number Diff line number Diff line change @@ -106,17 +106,33 @@ Here are some tools based on Rsbuild that have already set the `callerName` valu
106106
107107### context.devServer
108108
109- Dev server information, including the current dev server hostname and port number .
109+ Dev server information when running in dev mode. Available after the dev server has been created .
110110
111111- ** Type:**
112112
113113``` ts
114114type DevServer = {
115115 hostname: string ;
116116 port: number ;
117+ https: boolean ;
117118};
118119```
119120
121+ - ** Example:**
122+
123+ ``` ts
124+ import { createRsbuild } from ' @rsbuild/core' ;
125+
126+ async function main() {
127+ const rsbuild = createRsbuild ({
128+ // ...
129+ });
130+ await rsbuild .startDevServer ();
131+
132+ console .log (rsbuild .context .devServer ); // { hostname: 'localhost', port: 3000, https: false }
133+ }
134+ ```
135+
120136### context.action
121137
122138The current action type.
Original file line number Diff line number Diff line change @@ -106,17 +106,33 @@ export const myPlugin = {
106106
107107### context.devServer
108108
109- Dev server 相关信息,包含了当前 dev server 的 hostname 和端口号 。
109+ 在开发模式下运行时的 dev server 信息。仅在 dev server 创建后可访问 。
110110
111111- ** 类型:**
112112
113113``` ts
114114type DevServer = {
115115 hostname: string ;
116116 port: number ;
117+ https: boolean ;
117118};
118119```
119120
121+ - ** 示例:**
122+
123+ ``` ts
124+ import { createRsbuild } from ' @rsbuild/core' ;
125+
126+ async function main() {
127+ const rsbuild = createRsbuild ({
128+ // ...
129+ });
130+ await rsbuild .startDevServer ();
131+
132+ console .log (rsbuild .context .devServer ); // { hostname: 'localhost', port: 3000, https: false }
133+ }
134+ ```
135+
120136### context.action
121137
122138当前的动作类型。
You can’t perform that action at this time.
0 commit comments