@modern-js/main-doc 2.65.5 → 2.66.1-alpha.0

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.
Files changed (131) hide show
  1. package/docs/en/apis/app/hooks/src/app.mdx +20 -34
  2. package/docs/en/apis/app/hooks/src/modern.runtime.mdx +9 -0
  3. package/docs/en/apis/app/runtime/app/define-config.mdx +6 -0
  4. package/docs/en/community/blog/v2-release-note.mdx +1 -1
  5. package/docs/en/components/enable-micro-frontend.mdx +20 -3
  6. package/docs/en/components/micro-runtime-config.mdx +12 -13
  7. package/docs/en/components/reduck-notify.mdx +27 -0
  8. package/docs/en/configure/app/plugins.mdx +2 -2
  9. package/docs/en/configure/app/runtime/0-intro.mdx +63 -91
  10. package/docs/en/configure/app/tools/esbuild.mdx +1 -1
  11. package/docs/en/configure/app/tools/swc.mdx +1 -1
  12. package/docs/en/configure/app/usage.mdx +93 -69
  13. package/docs/en/guides/basic-features/render/_meta.json +1 -1
  14. package/docs/en/guides/basic-features/render/before-render.mdx +115 -0
  15. package/docs/en/guides/basic-features/routes.mdx +0 -95
  16. package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +3 -5
  17. package/docs/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +4 -2
  18. package/docs/en/guides/topic-detail/model/auto-actions.mdx +0 -4
  19. package/docs/en/guides/topic-detail/model/computed-state.mdx +0 -5
  20. package/docs/en/guides/topic-detail/model/define-model.mdx +0 -4
  21. package/docs/en/guides/topic-detail/model/faq.mdx +0 -5
  22. package/docs/en/guides/topic-detail/model/manage-effects.mdx +0 -5
  23. package/docs/en/guides/topic-detail/model/model-communicate.mdx +0 -5
  24. package/docs/en/guides/topic-detail/model/performance.mdx +0 -4
  25. package/docs/en/guides/topic-detail/model/quick-start.mdx +5 -7
  26. package/docs/en/guides/topic-detail/model/redux-integration.mdx +0 -4
  27. package/docs/en/guides/topic-detail/model/typescript-best-practice.mdx +0 -4
  28. package/docs/en/guides/topic-detail/model/use-model.mdx +0 -5
  29. package/docs/en/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -4
  30. package/docs/en/plugin/_meta.json +8 -7
  31. package/docs/en/plugin/cli-plugins/_meta.json +1 -1
  32. package/docs/en/plugin/cli-plugins/api.mdx +617 -0
  33. package/docs/en/plugin/cli-plugins/life-cycle.mdx +139 -0
  34. package/docs/en/plugin/cli-plugins/migration.mdx +98 -0
  35. package/docs/en/plugin/introduction.mdx +119 -47
  36. package/docs/en/plugin/official/_meta.json +12 -0
  37. package/docs/en/plugin/official/cli-plugins/_meta.json +1 -0
  38. package/docs/en/plugin/official/cli-plugins.mdx +6 -0
  39. package/docs/en/plugin/official/rsbuild-plugins.mdx +3 -0
  40. package/docs/en/plugin/plugin-system.mdx +237 -0
  41. package/docs/en/plugin/runtime-plugins/_meta.json +1 -0
  42. package/docs/en/plugin/runtime-plugins/api.mdx +165 -0
  43. package/docs/en/plugin/runtime-plugins/life-cycle.mdx +29 -0
  44. package/docs/en/plugin/runtime-plugins/migration.mdx +101 -0
  45. package/docs/en/plugin/server-plugins/api.mdx +3 -0
  46. package/docs/en/plugin/server-plugins/life-cycle.mdx +3 -0
  47. package/docs/zh/apis/app/hooks/src/app.mdx +18 -26
  48. package/docs/zh/apis/app/hooks/src/modern.runtime.mdx +9 -0
  49. package/docs/zh/apis/app/runtime/app/define-config.mdx +5 -0
  50. package/docs/zh/community/blog/v2-release-note.mdx +1 -1
  51. package/docs/zh/components/enable-micro-frontend.mdx +19 -12
  52. package/docs/zh/components/micro-runtime-config.mdx +3 -3
  53. package/docs/zh/components/reduck-notify.mdx +27 -0
  54. package/docs/zh/configure/app/plugins.mdx +2 -2
  55. package/docs/zh/configure/app/runtime/0-intro.mdx +67 -86
  56. package/docs/zh/configure/app/tools/esbuild.mdx +1 -1
  57. package/docs/zh/configure/app/tools/swc.mdx +1 -1
  58. package/docs/zh/configure/app/usage.mdx +44 -21
  59. package/docs/zh/guides/basic-features/render/_meta.json +1 -1
  60. package/docs/zh/guides/basic-features/render/before-render.mdx +115 -0
  61. package/docs/zh/guides/basic-features/routes.mdx +0 -95
  62. package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +3 -5
  63. package/docs/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +4 -2
  64. package/docs/zh/guides/topic-detail/model/auto-actions.mdx +0 -4
  65. package/docs/zh/guides/topic-detail/model/computed-state.mdx +0 -4
  66. package/docs/zh/guides/topic-detail/model/define-model.mdx +1 -4
  67. package/docs/zh/guides/topic-detail/model/faq.mdx +0 -5
  68. package/docs/zh/guides/topic-detail/model/manage-effects.mdx +0 -4
  69. package/docs/zh/guides/topic-detail/model/model-communicate.mdx +1 -4
  70. package/docs/zh/guides/topic-detail/model/performance.mdx +0 -4
  71. package/docs/zh/guides/topic-detail/model/quick-start.mdx +7 -8
  72. package/docs/zh/guides/topic-detail/model/redux-integration.mdx +0 -4
  73. package/docs/zh/guides/topic-detail/model/typescript-best-practice.mdx +0 -4
  74. package/docs/zh/guides/topic-detail/model/use-model.mdx +0 -5
  75. package/docs/zh/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -4
  76. package/docs/zh/plugin/_meta.json +8 -7
  77. package/docs/zh/plugin/cli-plugins/_meta.json +1 -1
  78. package/docs/zh/plugin/cli-plugins/api.mdx +617 -0
  79. package/docs/zh/plugin/cli-plugins/life-cycle.mdx +139 -0
  80. package/docs/zh/plugin/cli-plugins/migration.mdx +98 -0
  81. package/docs/zh/plugin/introduction.mdx +92 -20
  82. package/docs/zh/plugin/official/_meta.json +12 -0
  83. package/docs/zh/plugin/official/cli-plugins/_meta.json +1 -0
  84. package/docs/zh/plugin/official/cli-plugins.mdx +6 -0
  85. package/docs/zh/plugin/official/rsbuild-plugins.mdx +3 -0
  86. package/docs/zh/plugin/plugin-system.mdx +239 -0
  87. package/docs/zh/plugin/runtime-plugins/_meta.json +1 -0
  88. package/docs/zh/plugin/runtime-plugins/api.mdx +166 -0
  89. package/docs/zh/plugin/runtime-plugins/life-cycle.mdx +29 -0
  90. package/docs/zh/plugin/runtime-plugins/migration.mdx +101 -0
  91. package/docs/zh/plugin/server-plugins/api.mdx +3 -0
  92. package/docs/zh/plugin/server-plugins/life-cycle.mdx +3 -0
  93. package/i18n.json +4 -0
  94. package/package.json +3 -2
  95. package/src/components/Footer/index.tsx +1 -1
  96. package/src/components/Mermaid/index.tsx +60 -0
  97. package/src/components/Mermaid/style.scss +221 -0
  98. package/docs/en/plugin/cli-plugins.mdx +0 -6
  99. package/docs/en/plugin/plugin-system/_meta.json +0 -10
  100. package/docs/en/plugin/plugin-system/extend.mdx +0 -163
  101. package/docs/en/plugin/plugin-system/hook-list.mdx +0 -711
  102. package/docs/en/plugin/plugin-system/hook.mdx +0 -188
  103. package/docs/en/plugin/plugin-system/implement.mdx +0 -243
  104. package/docs/en/plugin/plugin-system/introduction.mdx +0 -95
  105. package/docs/en/plugin/plugin-system/lifecycle.mdx +0 -16
  106. package/docs/en/plugin/plugin-system/plugin-api.mdx +0 -138
  107. package/docs/en/plugin/plugin-system/relationship.mdx +0 -119
  108. package/docs/en/plugin/rsbuild-plugins.mdx +0 -3
  109. package/docs/zh/plugin/cli-plugins.mdx +0 -6
  110. package/docs/zh/plugin/plugin-system/_meta.json +0 -10
  111. package/docs/zh/plugin/plugin-system/extend.mdx +0 -163
  112. package/docs/zh/plugin/plugin-system/hook-list.mdx +0 -715
  113. package/docs/zh/plugin/plugin-system/hook.mdx +0 -173
  114. package/docs/zh/plugin/plugin-system/implement.mdx +0 -250
  115. package/docs/zh/plugin/plugin-system/introduction.mdx +0 -94
  116. package/docs/zh/plugin/plugin-system/lifecycle.mdx +0 -16
  117. package/docs/zh/plugin/plugin-system/plugin-api.mdx +0 -138
  118. package/docs/zh/plugin/plugin-system/relationship.mdx +0 -119
  119. package/docs/zh/plugin/rsbuild-plugins.mdx +0 -4
  120. /package/docs/en/plugin/{cli-plugins → official/cli-plugins}/plugin-bff.mdx +0 -0
  121. /package/docs/en/plugin/{cli-plugins → official/cli-plugins}/plugin-ssg.mdx +0 -0
  122. /package/docs/en/plugin/{cli-plugins → official/cli-plugins}/plugin-swc.mdx +0 -0
  123. /package/docs/en/plugin/{cli-plugins → official/cli-plugins}/plugin-tailwind.mdx +0 -0
  124. /package/docs/en/plugin/{rsbuild-plugins → official/rsbuild-plugins}/_meta.json +0 -0
  125. /package/docs/en/plugin/{rsbuild-plugins → official/rsbuild-plugins}/plugin-esbuild.mdx +0 -0
  126. /package/docs/zh/plugin/{cli-plugins → official/cli-plugins}/plugin-bff.mdx +0 -0
  127. /package/docs/zh/plugin/{cli-plugins → official/cli-plugins}/plugin-ssg.mdx +0 -0
  128. /package/docs/zh/plugin/{cli-plugins → official/cli-plugins}/plugin-swc.mdx +0 -0
  129. /package/docs/zh/plugin/{cli-plugins → official/cli-plugins}/plugin-tailwind.mdx +0 -0
  130. /package/docs/zh/plugin/{rsbuild-plugins → official/rsbuild-plugins}/_meta.json +0 -0
  131. /package/docs/zh/plugin/{rsbuild-plugins → official/rsbuild-plugins}/plugin-esbuild.mdx +0 -0
@@ -0,0 +1,139 @@
1
+ # Life Cycle
2
+
3
+ import Mermaid from '@site/src/components/Mermaid';
4
+
5
+ <Mermaid>
6
+ {`
7
+ flowchart TD
8
+ init{{"CLI Init"}}
9
+ env(Initialize Environment Variables)
10
+ load_config(Load User Configuration File)
11
+ cli_plugin(Load CLI Plugin)
12
+ registry_hooks(Register Hooks Function<br><sub>Execute plugin setup function, register hooks defined in the plugin, and the logic in the plugin setup will also be executed here</sub>)
13
+
14
+ app_tools{{"app-tools"}}
15
+
16
+ config(config)
17
+ onPrepare(onPrepare)
18
+ addCommand(addCommand)
19
+ addWatchFiles(addWatchFiles)
20
+ onFileChanged(onFileChanged)
21
+ onBeforeExit(onBeforeExit<br><sub>Triggered by SIGINT, SIGTERM, unhandledRejection, uncaughtException events</sub>)
22
+
23
+ onBeforeDev(onBeforeDev)
24
+ onBeforeRestart(onBeforeRestart<br><sub>Triggered when modified files require a service restart</sub>)
25
+ onBeforeBuild(onBeforeBuild<br><sub>Triggered in standalone BFF projects</sub>)
26
+ onAfterBuild(onAfterBuild<br><sub>Triggered in standalone BFF projects</sub>)
27
+ modifyServerRoutes(modifyServerRoutes)
28
+ modifyHtmlPartials(modifyHtmlPartials)
29
+
30
+ onPrepare_fork(onPrepare)
31
+ addCommand_fork(addCommand)
32
+ onFileChanged_fork(onFileChanged)
33
+
34
+ registry_rsbuild_hooks(Register rsbuild Hooks<br><sub>This only registers the rsbuild hooks; the specific execution timing is determined by the rsbuild plugin mechanism</sub>)
35
+
36
+ modifyBundlerChain(modifyBundlerChain)
37
+ modifyRsbuildConfig(modifyRsbuildConfig)
38
+ modifyRspackConfig(modifyRspackConfig)
39
+ modifyWebpackChain(modifyWebpackChain)
40
+ modifyWebpackConfig(modifyWebpackConfig)
41
+
42
+ onBeforeBuild_rsbuild(onBeforeBuild)
43
+ onAfterBuild_rsbuild(onAfterBuild)
44
+ onDevCompileDone(onDevCompileDone)
45
+ onBeforeCreateCompiler(onBeforeCreateCompiler)
46
+ onAfterCreateCompiler(onAfterCreateCompiler)
47
+ onAfterDev(onAfterDev<br><sub>Corresponds to the onAfterStartDevServer Hook of rsbuild</sub>)
48
+
49
+ dev[/dev/]
50
+ build[/build/]
51
+ extra_command[/.../]
52
+
53
+ dev_fork[/dev/]
54
+ build_fork[/build/]
55
+ serve[/serve/]
56
+ deploy[/deploy/]
57
+ inspect[/inspect/]
58
+ upgrade[/upgrade/]
59
+
60
+ onPrepare_fork --> modifyServerRoutes
61
+ modifyServerRoutes --> modifyHtmlPartials
62
+ modifyHtmlPartials --> registry_rsbuild_hooks
63
+ registry_rsbuild_hooks --> modifyBundlerChain
64
+ modifyBundlerChain --> modifyRsbuildConfig
65
+ modifyRsbuildConfig --> modifyRspackConfig
66
+ modifyRspackConfig --> modifyWebpackChain
67
+ modifyWebpackChain --> modifyWebpackConfig
68
+ registry_rsbuild_hooks --> onBeforeBuild_rsbuild
69
+ onBeforeBuild_rsbuild --> onAfterBuild_rsbuild
70
+ onAfterBuild_rsbuild --> onDevCompileDone
71
+ onDevCompileDone --> onBeforeCreateCompiler
72
+ onBeforeCreateCompiler --> onAfterCreateCompiler
73
+ onAfterCreateCompiler --> onAfterDev
74
+
75
+ dev_fork --> onBeforeDev
76
+ onBeforeDev --> onFileChanged_fork
77
+ onFileChanged_fork --> onBeforeRestart
78
+
79
+ build_fork --> onBeforeBuild
80
+ onBeforeBuild --> onAfterBuild
81
+
82
+ app_tools --- spacer5[ ] --- spacer6[ ] --- spacer7[ ] --- spacer8[ ] --- spacer9[ ] --> onPrepare_fork
83
+ onPrepare_fork --> addCommand_fork
84
+ addCommand_fork --> dev_fork
85
+ addCommand_fork --> build_fork
86
+ addCommand_fork --> serve
87
+ addCommand_fork --> deploy
88
+ addCommand_fork --> inspect
89
+ addCommand_fork --> upgrade
90
+
91
+ init --> env
92
+ env --> load_config
93
+ load_config --> cli_plugin
94
+ cli_plugin --> registry_hooks
95
+
96
+ registry_hooks --> config
97
+ config --> onPrepare
98
+ onPrepare --> addCommand
99
+
100
+ addCommand --> dev
101
+ addCommand --> build
102
+ addCommand --> extra_command
103
+
104
+ dev --> addWatchFiles
105
+ addWatchFiles --> onFileChanged
106
+
107
+ onFileChanged --> onBeforeExit
108
+ build --- spacer[ ] --- spacer2[ ] --> onBeforeExit
109
+ extra_command --- spacer3[ ] --- spacer4[ ] --> onBeforeExit
110
+
111
+ style init fill:#FDE68A;
112
+ style app_tools fill:#FDE68A;
113
+ style env stroke-dasharray:5 5,fill:#86EFAC;
114
+ style registry_rsbuild_hooks stroke-dasharray:5 5,fill:#9CA3AF;
115
+ style load_config stroke-dasharray:5 5,fill:#86EFAC;
116
+ style cli_plugin stroke-dasharray:5 5,fill:#86EFAC;
117
+ style registry_hooks stroke-dasharray:5 5,fill:#9CA3AF;
118
+
119
+ style dev fill:#7DD3FC;
120
+ style build fill:#7DD3FC;
121
+ style extra_command fill:#7DD3FC;
122
+ style dev_fork fill:#7DD3FC;
123
+ style build_fork fill:#7DD3FC;
124
+ style serve fill:#7DD3FC;
125
+ style upgrade fill:#7DD3FC;
126
+ style deploy fill:#7DD3FC;
127
+ style inspect fill:#7DD3FC;
128
+
129
+ style spacer fill:none,stroke:none,height:0px;
130
+ style spacer2 fill:none,stroke:none,height:0px;
131
+ style spacer3 fill:none,stroke:none,height:0px;
132
+ style spacer4 fill:none,stroke:none,height:0px;
133
+ style spacer5 fill:none,stroke:none,height:0px;
134
+ style spacer6 fill:none,stroke:none,height:0px;
135
+ style spacer7 fill:none,stroke:none,height:0px;
136
+ style spacer8 fill:none,stroke:none,height:0px;
137
+ style spacer9 fill:none,stroke:none,height:0px;
138
+ `}
139
+ </Mermaid>
@@ -0,0 +1,98 @@
1
+ # Plugin Migration
2
+
3
+ ### Migration Background
4
+
5
+ The Modern.js plugin system is constantly evolving. To provide a clearer API and more powerful features, we've optimized the definition and usage of CLI plugins. While the old plugin syntax is still supported for compatibility, we strongly recommend migrating according to this guide to take full advantage of the new plugin system.
6
+
7
+ ### Migration Steps Overview
8
+
9
+ 1. **Update Plugin Type Definition:** Replace the `CliPlugin` type with `CliPluginFuture`.
10
+ 2. **Adjust Hook Invocation:** Migrate from the `return hooks` pattern to direct `api.xxx` calls.
11
+ 3. **Replace Changed APIs:** Refer to the detailed API mapping table and update your code.
12
+
13
+ ### Detailed Migration Steps
14
+
15
+ #### Update Plugin Type Definition
16
+
17
+ This is the first and most crucial step of the migration. It ensures that your plugin interacts correctly with the new plugin system.
18
+
19
+ ```typescript
20
+ // Old Syntax
21
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
22
+
23
+ const plugin: CliPlugin<AppTools<'shared'>> = { ... };
24
+
25
+ // New Syntax
26
+ import type { CliPluginFuture, AppTools } from '@modern-js/app-tools';
27
+
28
+ const plugin: CliPluginFuture<AppTools<'shared'>> = { ... };
29
+ ```
30
+
31
+ **Explanation:** The `CliPluginFuture` type is the standard definition for new plugins, providing better type inference and a clearer API structure.
32
+
33
+ #### Adjust Hook Invocation
34
+
35
+ The new plugin system recommends using the `api` object to directly call Hooks. This approach is more intuitive and easier to maintain.
36
+
37
+ ```typescript
38
+ // Old Syntax (return hooks)
39
+ {
40
+ setup: () => ({
41
+ commands({ program }) { /*...*/ }
42
+ })
43
+ }
44
+
45
+ // New Syntax (api.xxx)
46
+ {
47
+ setup: api => {
48
+ api.addCommand(({ program }) => { /*...*/ })
49
+ }
50
+ }
51
+ ```
52
+
53
+ **Explanation:** The `api` object provides all available Hooks and utility methods.
54
+
55
+ #### Replace Changed APIs
56
+
57
+ To maintain API consistency and clarity, we've adjusted the names of some APIs. The following table lists all changed APIs and their old and new counterparts:
58
+
59
+ | Old API | New API | Description |
60
+ | :----------------------- | :---------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
61
+ | `useAppContext` | `getAppContext` | Gets the application context information. |
62
+ | `useConfigContext` | `getConfig` | Gets the configuration defined in the user's configuration file. |
63
+ | `useResolvedConfigContext` | `getNormalizedConfig` | Gets the final configuration after processing by plugins. |
64
+ | `beforeConfig` | (Defined directly in `setup`) | The `beforeConfig` Hook is no longer needed. Write related logic directly in the `setup` function. |
65
+ | `prepare` | `onPrepare` | The preparation stage before running the main process. |
66
+ | `afterPrepare` | `onAfterPrepare` (Deprecated) | Executes after `onPrepare`, but may be deprecated in future versions. It's recommended to merge the logic into `onPrepare`. |
67
+ | `beforePrintInstructions`| `onBeforePrintInstructions` | Executes before printing log messages. |
68
+ | `commands` | `addCommand` | Adds a new CLI command. |
69
+ | `watchFiles` | `addWatchFiles` | Adds files to be watched. |
70
+ | `fileChange` | `onFileChanged` | Listens for file change events. |
71
+ | `beforeCreateCompiler` | `onBeforeCreateCompiler` | Executes before creating the compiler. |
72
+ | `afterCreateCompiler` | `onAfterCreateCompiler` | Executes after creating the compiler. |
73
+ | `beforeBuild` | `onBeforeBuild` | Executes before building. |
74
+ | `afterBuild` | `onAfterBuild` | Executes after building. |
75
+ | `beforeDev` | `onBeforeDev` | Executes before running the `dev` command. |
76
+ | `afterDev` | `onDevCompileDone` | Executes after the `dev` command compilation is complete. |
77
+ | `beforeExit` | `onBeforeExit` | Executes before the process exits. |
78
+ | `htmlPartials` | `modifyHtmlPartials` | Modifies HTML template partials. |
79
+
80
+ **Explanation:** Please carefully review your code and ensure that all old APIs have been replaced with the new APIs.
81
+
82
+ ### Frequently Asked Questions
83
+
84
+ **Q: Will my plugin still work after the migration?**
85
+
86
+ A: As long as you have correctly completed all the steps in this guide, your plugin should work normally. If you encounter any problems, please refer to the official Modern.js documentation or seek community support.
87
+
88
+ **Q: Do I have to migrate my plugin immediately?**
89
+
90
+ A: While the old plugin syntax is still supported, we strongly recommend migrating as soon as possible. The new plugin system offers better performance and richer features, and migration is worthwhile in the long run.
91
+
92
+ **Q: Where can I find more information about the new plugin system?**
93
+
94
+ A: Please refer to the official Modern.js documentation, especially the section on the plugin system. You can also refer to examples of other migrated plugins to understand best practices.
95
+
96
+ ### Summary
97
+
98
+ With this detailed migration guide, we hope to help you smoothly migrate your CLI plugins to the new Modern.js plugin system. If you encounter any problems during the migration, please feel free to ask us for help.
@@ -1,77 +1,149 @@
1
- # Plugin
1
+ # Introduction
2
2
 
3
- In Modern.js, you can directly use two types of plugins: Modern.js framework plugins and Rsbuild plugins.
3
+ Modern.js provides a powerful plugin system that allows developers to extend the framework's functionality, customize the build process, and meet a variety of personalized development needs. Whether you want to add a custom command, optimize build output, or implement a unique deployment solution, Modern.js's plugin system provides robust support.
4
4
 
5
- ## Modern.js Framework Plugin
5
+ ## Why Plugins?
6
6
 
7
- Modern.js has its own framework plugin system. You can use Modern.js plugins by configuring the [`plugins`](/configure/app/plugins) field in `modern.config.ts`.
7
+ In web application development, we often encounter needs that the framework itself cannot directly satisfy, such as:
8
+
9
+ - **I want to add a custom command-line tool to help me automate some tasks.**
10
+ - **I want to be able to handle a new file format, such as `.xyz`.**
11
+ - **I need to perform some initialization operations before the application starts.**
12
+ - **I want to perform special processing on the generated CSS files.**
13
+ - **I need to customize the application's routing logic or add some server-side middleware.**
14
+
15
+ Without a plugin system, these requirements might require modifying the framework's source code or resorting to cumbersome hacks. Modern.js's plugin system offers an elegant, flexible, and maintainable solution.
16
+
17
+ ## When to Use Which Plugin?
18
+
19
+ Modern.js offers two main types of plugins: Modern.js framework plugins and Rsbuild build plugins. The choice of which plugin to use depends on your specific needs:
20
+
21
+ - **Rsbuild Build Plugins:** If your needs are closely related to the build process, especially involving modifications to Webpack or Rspack configuration, then you should choose an Rsbuild plugin. For example:
22
+ - Modifying Webpack/Rspack `loader` or `plugin` configurations.
23
+ - Handling new file types.
24
+ - Modifying or compiling file contents.
25
+ - Optimizing or processing build artifacts.
26
+
27
+ - **Modern.js Framework Plugins:** If your needs relate to the extension of Modern.js framework itself, runtime behavior, or server-side logic, then you should choose a Modern.js plugin. For example:
28
+ - Adding custom command-line commands.
29
+ - Modifying the application's routing configuration.
30
+ - Customizing the application's rendering process (e.g., SSR).
31
+ - Adding server-side middleware or handler functions.
32
+
33
+ In short, use Rsbuild plugins when you need to modify Webpack/Rspack configurations; use Modern.js plugins for other framework-related extensions.
34
+
35
+ ## Modern.js Framework Plugins
8
36
 
9
37
  ### Plugin Types
10
38
 
11
- Framework plugins can be categorized into three types:
39
+ Modern.js framework plugins can be further divided into three categories:
40
+
41
+ #### CLI Plugins
42
+
43
+ CLI plugins are used to provide additional functionality when running `modern` commands in the application, such as adding commands, modifying configurations, and listening for file changes. Most build-related capabilities can be implemented through CLI plugins.
44
+
45
+ CLI plugins can be configured via the `plugins` field in `modern.config.ts`.
46
+
47
+ ```ts title="modern.config.ts"
48
+ // an example for bff
49
+ import { appTools, defineConfig } from '@modern-js/app-tools';
50
+ import { bffPlugin } from '@modern-js/plugin-bff';
51
+
52
+ export default defineConfig({
53
+ plugins: [appTools(), bffPlugin()],
54
+ });
55
+ ```
12
56
 
13
- 1. [CLI Plugins](/plugin/cli-plugins): These are used to provide additional functionality when the Modern.js commands are executed in the application. Examples include adding commands, modifying configuration, and monitoring files. Most build-related capabilities can be achieved through CLI plugins.
14
- 2. Server Plugins: These add extra functionality when the application receives requests. Examples include adding middleware and modifying request responses.
15
- 3. Runtime Plugins: These provide additional functionality when the application runs React code. Examples include performing initialization actions and wrapping React higher-order components.
57
+ #### Runtime Plugins
16
58
 
17
- :::note
18
- Server plugins and Runtime plugins are coming soon.
59
+ Runtime plugins are used to provide additional functionality when the application is running React code, such as performing initialization behaviors and implementing React Higher-Order Component (HOC) encapsulation.
60
+
61
+ Runtime plugins are configured via the `plugins` field in `src/modern.runtime.ts`.
62
+
63
+ ```ts title="src/modern.runtime.ts"
64
+ import { defineRuntimeConfig } from '@modern-js/runtime';
65
+ import { routerPlugin } from '@modern-js/runtime/router';
66
+
67
+ export default defineRuntimeConfig({
68
+ plugins: [routerPlugin()],
69
+ });
70
+ ```
71
+
72
+ {/* #### Server Plugins
73
+
74
+ Server plugins are used to provide additional functionality when the application receives requests, such as adding middleware and modifying request responses.
75
+
76
+ Server plugins are configured via the `plugins` field in `server/modern.server.ts`.
77
+
78
+ ```ts title="src/modern.server.ts"
79
+ import { defineConfig } from '@modern-js/app-tools/server';
80
+ import bffPlugin from '@modern-js/plugin-bff/server';
81
+
82
+ export default defineConfig({
83
+ plugins: [bffPlugin()],
84
+ });
85
+ ``` */}
86
+
87
+ :::tip
88
+ Modern.js officially uses the new plugin mechanism starting from `MAJOR_VERSION.66.0`.
89
+
90
+ If your current version is lower than MAJOR_VERSION.66.0, you can upgrade by running `npx modern upgrade`.
19
91
  :::
20
92
 
21
93
  ### Developing Plugins
22
94
 
23
- If you need to develop Modern.js framework plugins, you can read [Modern.js Plugin System](/plugin/plugin-system/introduction) for more information.
95
+ If you need to develop Modern.js framework plugins, please read [Modern.js Plugin System](/plugin/plugin-system) for more information.
96
+
97
+ ## Rsbuild Build Plugins
24
98
 
25
- Rsbuild is the build tool of Modern.js. You can modify the default build behavior and add various additional features by adding the Rsbuild plugin, including but not limited to:
99
+ Rsbuild is the underlying build tool for Modern.js. By adding Rsbuild plugins, you can modify the default build behavior and add various additional functionalities, including but not limited to:
26
100
 
27
- - Modifying Rspack configurations
28
- - Processing new file types
101
+ - Modifying Rsbuild configuration
102
+ - Handling new file types
29
103
  - Modifying or compiling files
30
104
  - Deploying artifacts
31
105
 
32
- You can register the Rsbuild plugin through the `builderPlugins` option in `modern.config.ts`, see [builderPlugins](/configure/app/builder-plugins) for details.
106
+ You can register Rsbuild plugins in `modern.config.ts` via the `builderPlugins` option. See [builderPlugins](/configure/app/builder-plugins.html) for details.
33
107
 
34
108
  :::tip
35
- Modern.js has upgraded the build tool to [Rsbuild](https://rsbuild.dev/) starting from `MAJOR_VERSION.46.0`.
109
+ Starting from `MAJOR_VERSION.46.0`, Modern.js upgraded its underlying build tool to [Rsbuild](https://rsbuild.dev/).
36
110
 
37
- If your current version is lower than MAJOR_VERSION.46.0, you can upgrade by executing `npx modern upgrade`.
111
+ If your current version is lower than MAJOR_VERSION.46.0, you can upgrade by running `npx modern upgrade`.
38
112
  :::
39
113
 
40
114
  :::info
41
- For more information about the Rsbuild plugin system, you can read [Rsbuild Official Site - Plugins](https://rsbuild.dev/plugins/list/index).
115
+ You can read [Rsbuild Official Website - Plugins](https://rsbuild.dev/plugins/list/index) to learn more about the Rsbuild plugin system.
42
116
  :::
43
117
 
44
- ## Rsbuild Plugin
45
-
46
118
  ### Official Plugins
47
119
 
48
- #### Builtin Plugins
49
-
50
- Here are the official Rsbuild plugins built into Modern.js:
51
-
52
- | Plugin Name | Introduce | Modern.js Link |
53
- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
54
- | [React Plugin](https://rsbuild.dev/plugins/list/plugin-react) | Provides support for React | - |
55
- | [SVGR Plugin](https://rsbuild.dev/plugins/list/plugin-svgr) | Support convert SVG to React components | [output.disableSvgr](/configure/app/output/disable-svgr)<br />[output.svgDefaultExport](/configure/app/output/svg-default-export) |
56
- | [Styled Components Plugin](https://github.com/rspack-contrib/rsbuild-plugin-styled-components) | Provides compile-time support for styled-components | [tools.styledComponents](/configure/app/tools/styled-components.html) |
57
- | [Assets Retry Plugin](https://rsbuild.dev/plugins/list/plugin-assets-retry) | Used to automatically resend requests when static assets fail to load | [output.assetsRetry](/configure/app/output/assets-retry.html) |
58
- | [Type Check Plugin](https://github.com/rspack-contrib/rsbuild-plugin-type-check) | Used to run TypeScript type checker on a separate process | [output.disableTsChecker](/configure/app/output/disable-ts-checker.html)<br />[tools.tsChecker](/configure/app/tools/ts-checker.html) |
59
- | [Node Polyfill Plugin](https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill) | Used to inject polyfills of Node core modules in the browser side | [output.disableNodePolyfill](/configure/app/output/disable-node-polyfill.html) |
60
- | [Source Build Plugin](https://github.com/rspack-contrib/rsbuild-plugin-source-build) | Supports referencing source code from other subdirectories | [experiments.sourceBuild](/configure/app/experiments/source-build.html) |
61
- | [Check Syntax Plugin](https://github.com/rspack-contrib/rsbuild-plugin-check-syntax) | Used to analyze the syntax compatibility of artifacts | [security.checkSyntax](/configure/app/security/check-syntax.html) |
62
- | [CSS Minimizer Plugin](https://github.com/rspack-contrib/rsbuild-plugin-css-minimizer) | Used to customize CSS minimizer, switch to [cssnano](https://cssnano.co/) or other tools for CSS compression | [tools.minifyCss](/configure/app/tools/minify-css.html) |
63
- | [Pug Plugin](https://github.com/rspack-contrib/rsbuild-plugin-pug) | Provides support for the Pug template engine | [tools.pug](/configure/app/tools/pug.html) |
64
- | [Rem Plugin](https://github.com/rspack-contrib/rsbuild-plugin-rem) | Implements the rem adaptive layout for mobile pages | [output.convertToRem](/configure/app/output/convert-to-rem.html) |
65
- | [YAML Plugin](https://github.com/rspack-contrib/rsbuild-plugin-yaml) | Used to import YAML files and convert them into JavaScript objects | [TOML File](/guides/basic-features/static-assets/json-files.html#toml-file) |
66
- | [TOML Plugin](https://github.com/rspack-contrib/rsbuild-plugin-toml) | Used to import TOML files and convert them into JavaScript objects | [YAML File](/guides/basic-features/static-assets/json-files.html#yaml-file) |
67
-
68
- #### Un-builtin Plugins
69
-
70
- Here are the official Rsbuild plugins that are not built into Modern.js:
71
-
72
- - [Image Compress Plugin](https://github.com/rspack-contrib/rsbuild-plugin-image-compress): Compress the image resources used in the project.
73
- - [Stylus Plugin](https://rsbuild.dev/plugins/list/plugin-stylus): Use Stylus as the CSS preprocessor.
74
- - [UMD Plugin](https://github.com/rspack-contrib/rsbuild-plugin-umd): Used to build outputs in UMD format.
120
+ #### Built-in Plugins
121
+
122
+ The following are official Rsbuild plugins that are already built into Modern.js. They can be enabled without installation:
123
+
124
+ | Plugin | Description | Modern.js Link |
125
+ | -------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
126
+ | [React Plugin](https://rsbuild.dev/zh/plugins/list/plugin-react) | Provides support for React | - |
127
+ | [SVGR Plugin](https://rsbuild.dev/zh/plugins/list/plugin-svgr) | Supports converting SVG images into React components | [output.disableSvgr](/configure/app/output/disable-svgr)<br />[output.svgDefaultExport](/configure/app/output/svg-default-export) |
128
+ | [Styled Components Plugin](https://github.com/rspack-contrib/rsbuild-plugin-styled-components) | Provides compile-time support for styled-components | [tools.styledComponents](/configure/app/tools/styled-components.html) |
129
+ | [Assets Retry Plugin](https://rsbuild.dev/zh/plugins/list/plugin-assets-retry) | Automatically retries requests when static asset loading fails | [output.assetsRetry](/configure/app/output/assets-retry.html) |
130
+ | [Type Check Plugin](https://github.com/rspack-contrib/rsbuild-plugin-type-check) | Runs TypeScript type checking in a separate process | [output.disableTsChecker](/configure/app/output/disable-ts-checker.html)<br />[tools.tsChecker](/configure/app/tools/ts-checker.html) |
131
+ | [Node Polyfill Plugin](https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill) | Injects polyfills for Node core modules in the browser | [output.disableNodePolyfill](/configure/app/output/disable-node-polyfill.html) |
132
+ | [Source Build Plugin](https://github.com/rspack-contrib/rsbuild-plugin-source-build) | For monorepo scenarios, supports referencing source code from other subdirectories and completing builds and hot updates | [experiments.sourceBuild](/configure/app/experiments/source-build.html) |
133
+ | [Check Syntax Plugin](https://github.com/rspack-contrib/rsbuild-plugin-check-syntax) | Analyzes the syntax compatibility of the build artifacts to determine if there are any advanced syntax features that cause compatibility issues | [security.checkSyntax](/configure/app/security/check-syntax.html) |
134
+ | [CSS Minimizer Plugin](https://github.com/rspack-contrib/rsbuild-plugin-css-minimizer) | Used to customize the CSS compression tool, switch to [cssnano](https://cssnano.co/) or other tools for CSS compression | [tools.minifyCss](/configure/app/tools/minify-css.html) |
135
+ | [Pug Plugin](https://github.com/rspack-contrib/rsbuild-plugin-pug) | Provides support for the Pug template engine | [tools.pug](/configure/app/tools/pug.html) |
136
+ | [Rem Plugin](https://github.com/rspack-contrib/rsbuild-plugin-rem) | Implements rem adaptive layout for mobile pages | [output.convertToRem](/configure/app/output/convert-to-rem.html) |
137
+ | [YAML Plugin](https://github.com/rspack-contrib/rsbuild-plugin-yaml) | Used to reference YAML files and convert them to JavaScript objects | [YAML Files](/guides/basic-features/static-assets/json-files.html#yaml-files) |
138
+ | [TOML Plugin](https://github.com/rspack-contrib/rsbuild-plugin-toml) | Used to reference TOML files and convert them to JavaScript objects | [TOML Files](/guides/basic-features/static-assets/json-files.html#toml-files) |
139
+
140
+ #### Plugins Not Built-in
141
+
142
+ The following are official Rsbuild plugins that are not built into Modern.js:
143
+
144
+ - [Image Compress Plugin](https://github.com/rspack-contrib/rsbuild-plugin-image-compress): Compresses image resources used in the project.
145
+ - [Stylus Plugin](https://rsbuild.dev/zh/plugins/list/plugin-stylus): Uses Stylus as the CSS preprocessor.
146
+ - [UMD Plugin](https://github.com/rspack-contrib/rsbuild-plugin-umd): Used to build UMD format artifacts.
75
147
 
76
148
  import OtherPlugins from '@site-docs-en/components/other-plugins.mdx';
77
149
 
@@ -0,0 +1,12 @@
1
+ [
2
+ {
3
+ "type": "dir",
4
+ "name": "cli-plugins",
5
+ "label": "cli-plugins"
6
+ },
7
+ {
8
+ "type": "dir",
9
+ "name": "rsbuild-plugins",
10
+ "label": "rsbuild-plugins"
11
+ }
12
+ ]
@@ -0,0 +1 @@
1
+ ["plugin-tailwind", "plugin-bff", "plugin-ssg", "plugin-swc"]
@@ -0,0 +1,6 @@
1
+ # Overview
2
+
3
+ - [@modern-js/plugin-tailwindcss](/plugin/official/cli-plugins/plugin-tailwind): Enables the use of Tailwind CSS styles.
4
+ - [@modern-js/plugin-bff](/plugin/official/cli-plugins/plugin-bff): Provides BFF services and unified invocation capabilities.
5
+ - [@modern-js/plugin-ssg](/plugin/official/cli-plugins/plugin-ssg): Provides static site generation capabilities.
6
+ - [@modern-js/plugin-swc](/plugin/official/cli-plugins/plugin-swc): Provides SWC compilation support.
@@ -0,0 +1,3 @@
1
+ # Overview
2
+
3
+ - [@modern-js/plugin-esbuild](/plugin/official/rsbuild-plugins/plugin-esbuild): Provides esbuild compilation support.