Skip to content

Commit fd53ecb

Browse files
authored
docs: enhance rsbuild.context with access methods (#5266)
1 parent d56343e commit fd53ecb

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

website/docs/en/api/javascript-api/instance.mdx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,30 @@ This section describes all the properties and methods on the Rsbuild instance ob
44

55
## rsbuild.context
66

7-
`rsbuild.context` is a read-only object that provides some context information.
7+
`rsbuild.context` is a read-only object that provides some context information, which can be accessed in two ways:
8+
9+
1. Access through the `context` property of the Rsbuild instance:
10+
11+
```ts
12+
import { createRsbuild } from '@rsbuild/core';
13+
14+
const rsbuild = createRsbuild({
15+
// ...
16+
});
17+
18+
console.log(rsbuild.context);
19+
```
20+
21+
2. Access through the [api.context](/plugins/dev/core#apicontext) of the Rsbuild plugin:
22+
23+
```ts
24+
export const myPlugin = {
25+
name: 'my-plugin',
26+
setup(api) {
27+
console.log(api.context);
28+
},
29+
};
30+
```
831

932
### context.version
1033

website/docs/zh/api/javascript-api/instance.mdx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,30 @@
44

55
## rsbuild.context
66

7-
`rsbuild.context` 是一个只读对象,提供一些上下文信息。
7+
`context` 是一个只读对象,提供一些上下文信息,能够通过两种方式访问:
8+
9+
1. 通过 Rsbuild 实例的 `context` 属性访问:
10+
11+
```ts
12+
import { createRsbuild } from '@rsbuild/core';
13+
14+
const rsbuild = createRsbuild({
15+
// ...
16+
});
17+
18+
console.log(rsbuild.context);
19+
```
20+
21+
2. 通过 Rsbuild 插件的 [api.context](/plugins/dev/core#apicontext) 访问:
22+
23+
```ts
24+
export const myPlugin = {
25+
name: 'my-plugin',
26+
setup(api) {
27+
console.log(api.context);
28+
},
29+
};
30+
```
831

932
### context.version
1033

0 commit comments

Comments
 (0)