@modern-js/main-doc 0.0.0-nightly-20240804170628 → 0.0.0-nightly-20240806170721
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -200,7 +200,7 @@ Usage: modern inspect [options]
|
|
200
200
|
|
201
201
|
Options:
|
202
202
|
--env <env> view the configuration in the target environment (default: "development")
|
203
|
-
--output <output> Specify the path to output in the dist (default: "
|
203
|
+
--output <output> Specify the path to output in the dist (default: "./")
|
204
204
|
--verbose Show the full function in the result
|
205
205
|
-c --config <config> specify the configuration file, which can be a relative or absolute path
|
206
206
|
-h, --help show command help
|
@@ -674,17 +674,17 @@ export const myPlugin = (): ServerPlugin => ({
|
|
674
674
|
## Runtime
|
675
675
|
|
676
676
|
:::note
|
677
|
-
|
677
|
+
Currently, the Runtime plugin is not fully open, and the API does not guarantee stability. Use with caution.
|
678
678
|
:::
|
679
679
|
|
680
|
-
The Runtime plugin is mainly used
|
680
|
+
The Runtime plugin is mainly used by developers to add behaviors before application rendering and to modify components that need to be rendered.
|
681
681
|
|
682
|
-
### `
|
682
|
+
### `beforeRender`
|
683
683
|
|
684
|
-
- Function:
|
684
|
+
- Function: Add behaviors before application rendering
|
685
685
|
- Execution stage: Rendering (SSR/CSR).
|
686
|
-
- Hook model: `
|
687
|
-
- Type: `
|
686
|
+
- Hook model: `AsyncWorkflow`
|
687
|
+
- Type: `AsyncWorkflow<RuntimeContext, void>`
|
688
688
|
- Example:
|
689
689
|
|
690
690
|
```ts
|
@@ -693,27 +693,22 @@ import type { Plugin } from '@modern-js/runtime';
|
|
693
693
|
export const myPlugin = (): Plugin => ({
|
694
694
|
setup(api) {
|
695
695
|
return {
|
696
|
-
|
696
|
+
beforeRender(context) {
|
697
697
|
// do something
|
698
|
-
return next({ context });
|
699
698
|
},
|
700
699
|
};
|
701
700
|
},
|
702
701
|
});
|
703
702
|
```
|
704
703
|
|
705
|
-
### `
|
704
|
+
### `wrapRoot`
|
706
705
|
|
707
|
-
- Function:
|
706
|
+
- Function: Modify components that need to be rendered
|
708
707
|
- Execution stage: Rendering (SSR/CSR).
|
709
|
-
- Hook model: `
|
710
|
-
- Type: `
|
708
|
+
- Hook model: `Waterfall`
|
709
|
+
- Type: `Waterfall<React.ComponentType<any>>`
|
711
710
|
- Example:
|
712
711
|
|
713
|
-
:::note
|
714
|
-
When using the hoc hook, you need to copy the static properties of the original App component to the new component and pass through the props.
|
715
|
-
:::
|
716
|
-
|
717
712
|
```ts
|
718
713
|
import { createContext } from 'react';
|
719
714
|
import type { Plugin } from '@modern-js/runtime';
|
@@ -722,18 +717,15 @@ export const myPlugin = (): Plugin => ({
|
|
722
717
|
setup(api) {
|
723
718
|
const FooContext = createContext('');
|
724
719
|
return {
|
725
|
-
|
720
|
+
wrapRoot(App) {
|
726
721
|
const AppWrapper = (props: any) => {
|
727
722
|
return (
|
728
|
-
<FooContext.Provider
|
723
|
+
<FooContext.Provider value={'test'}>
|
729
724
|
<App {...props} />
|
730
725
|
</FooContext.Provider>
|
731
726
|
);
|
732
727
|
};
|
733
|
-
return
|
734
|
-
App: AppWrapper,
|
735
|
-
config
|
736
|
-
});
|
728
|
+
return AppWrapper;
|
737
729
|
},
|
738
730
|
};
|
739
731
|
},
|
@@ -200,7 +200,7 @@ Usage: modern inspect [options]
|
|
200
200
|
|
201
201
|
Options:
|
202
202
|
--env <env> 查看指定环境下的配置 (default: "development")
|
203
|
-
--output <output> 指定在 dist 目录下输出的路径 (default: "
|
203
|
+
--output <output> 指定在 dist 目录下输出的路径 (default: "./")
|
204
204
|
--verbose 在结果中展示函数的完整内容
|
205
205
|
-c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
|
206
206
|
-h, --help 显示命令帮助
|
@@ -680,14 +680,14 @@ export const myPlugin = (): ServerPlugin => ({
|
|
680
680
|
|
681
681
|
:::
|
682
682
|
|
683
|
-
Runtime
|
683
|
+
Runtime 插件主要用于开发者自定义应用渲染前行为和修改需要渲染的组件。
|
684
684
|
|
685
|
-
### `
|
685
|
+
### `beforeRender`
|
686
686
|
|
687
|
-
-
|
687
|
+
- 功能:在应用渲染之前增加行为
|
688
688
|
- 执行阶段:渲染(SSR/CSR)
|
689
|
-
- Hook 模型:`
|
690
|
-
- 类型:`
|
689
|
+
- Hook 模型:`AsyncWorkflow`
|
690
|
+
- 类型:`AsyncWorkflow<RuntimeContext, void>`
|
691
691
|
- 使用示例:
|
692
692
|
|
693
693
|
```ts
|
@@ -696,27 +696,22 @@ import type { Plugin } from '@modern-js/runtime';
|
|
696
696
|
export const myPlugin = (): Plugin => ({
|
697
697
|
setup(api) {
|
698
698
|
return {
|
699
|
-
|
699
|
+
beforeRender(context) {
|
700
700
|
// do something
|
701
|
-
return next({ context });
|
702
701
|
},
|
703
702
|
};
|
704
703
|
},
|
705
704
|
});
|
706
705
|
```
|
707
706
|
|
708
|
-
### `
|
707
|
+
### `wrapRoot`
|
709
708
|
|
710
709
|
- 功能:修改需要渲染的组件
|
711
710
|
- 执行阶段:渲染(SSR/CSR)
|
712
|
-
- Hook 模型:`
|
713
|
-
- 类型:`
|
711
|
+
- Hook 模型:`Waterfall`
|
712
|
+
- 类型:`Waterfall<React.ComponentType<any>>`
|
714
713
|
- 使用示例:
|
715
714
|
|
716
|
-
:::note
|
717
|
-
使用 hoc 钩子时,需要把原来的 App 组件的静态属性拷贝到新的组件上,并透传 props.
|
718
|
-
:::
|
719
|
-
|
720
715
|
```ts
|
721
716
|
import { createContext } from 'react';
|
722
717
|
import type { Plugin } from '@modern-js/runtime';
|
@@ -725,7 +720,7 @@ export const myPlugin = (): Plugin => ({
|
|
725
720
|
setup(api) {
|
726
721
|
const FooContext = createContext('');
|
727
722
|
return {
|
728
|
-
|
723
|
+
wrapRoot(App) {
|
729
724
|
const AppWrapper = (props: any) => {
|
730
725
|
return (
|
731
726
|
<FooContext.Provider store={'test'}>
|
@@ -733,10 +728,7 @@ export const myPlugin = (): Plugin => ({
|
|
733
728
|
</FooContext.Provider>
|
734
729
|
);
|
735
730
|
};
|
736
|
-
return
|
737
|
-
App: AppWrapper,
|
738
|
-
config
|
739
|
-
});
|
731
|
+
return AppWrapper
|
740
732
|
},
|
741
733
|
};
|
742
734
|
},
|
package/package.json
CHANGED
@@ -15,17 +15,17 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "0.0.0-nightly-
|
18
|
+
"version": "0.0.0-nightly-20240806170721",
|
19
19
|
"publishConfig": {
|
20
20
|
"registry": "https://registry.npmjs.org/",
|
21
21
|
"access": "public",
|
22
22
|
"provenance": true
|
23
23
|
},
|
24
24
|
"dependencies": {
|
25
|
-
"@modern-js/sandpack-react": "0.0.0-nightly-
|
25
|
+
"@modern-js/sandpack-react": "0.0.0-nightly-20240806170721"
|
26
26
|
},
|
27
27
|
"peerDependencies": {
|
28
|
-
"@modern-js/builder-doc": "0.0.0-nightly-
|
28
|
+
"@modern-js/builder-doc": "0.0.0-nightly-20240806170721"
|
29
29
|
},
|
30
30
|
"devDependencies": {
|
31
31
|
"classnames": "^2",
|
@@ -39,8 +39,8 @@
|
|
39
39
|
"@rspress/shared": "1.26.1",
|
40
40
|
"@types/node": "^16",
|
41
41
|
"@types/fs-extra": "9.0.13",
|
42
|
-
"@modern-js/doc-plugin-auto-sidebar": "0.0.0-nightly-
|
43
|
-
"@modern-js/builder-doc": "0.0.0-nightly-
|
42
|
+
"@modern-js/doc-plugin-auto-sidebar": "0.0.0-nightly-20240806170721",
|
43
|
+
"@modern-js/builder-doc": "0.0.0-nightly-20240806170721"
|
44
44
|
},
|
45
45
|
"scripts": {
|
46
46
|
"dev": "rspress dev",
|