@modern-js/main-doc 2.66.0 → 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 (51) 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/components/enable-micro-frontend.mdx +20 -3
  5. package/docs/en/components/micro-runtime-config.mdx +12 -13
  6. package/docs/en/components/reduck-notify.mdx +27 -0
  7. package/docs/en/configure/app/runtime/0-intro.mdx +63 -91
  8. package/docs/en/configure/app/usage.mdx +93 -69
  9. package/docs/en/guides/basic-features/render/_meta.json +1 -1
  10. package/docs/en/guides/basic-features/render/before-render.mdx +115 -0
  11. package/docs/en/guides/basic-features/routes.mdx +0 -95
  12. package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +3 -5
  13. package/docs/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +4 -2
  14. package/docs/en/guides/topic-detail/model/auto-actions.mdx +0 -4
  15. package/docs/en/guides/topic-detail/model/computed-state.mdx +0 -5
  16. package/docs/en/guides/topic-detail/model/define-model.mdx +0 -4
  17. package/docs/en/guides/topic-detail/model/faq.mdx +0 -5
  18. package/docs/en/guides/topic-detail/model/manage-effects.mdx +0 -5
  19. package/docs/en/guides/topic-detail/model/model-communicate.mdx +0 -5
  20. package/docs/en/guides/topic-detail/model/performance.mdx +0 -4
  21. package/docs/en/guides/topic-detail/model/quick-start.mdx +5 -7
  22. package/docs/en/guides/topic-detail/model/redux-integration.mdx +0 -4
  23. package/docs/en/guides/topic-detail/model/typescript-best-practice.mdx +0 -4
  24. package/docs/en/guides/topic-detail/model/use-model.mdx +0 -5
  25. package/docs/en/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -4
  26. package/docs/zh/apis/app/hooks/src/app.mdx +18 -26
  27. package/docs/zh/apis/app/hooks/src/modern.runtime.mdx +9 -0
  28. package/docs/zh/apis/app/runtime/app/define-config.mdx +5 -0
  29. package/docs/zh/components/enable-micro-frontend.mdx +19 -12
  30. package/docs/zh/components/micro-runtime-config.mdx +3 -3
  31. package/docs/zh/components/reduck-notify.mdx +27 -0
  32. package/docs/zh/configure/app/runtime/0-intro.mdx +67 -86
  33. package/docs/zh/configure/app/usage.mdx +44 -21
  34. package/docs/zh/guides/basic-features/render/_meta.json +1 -1
  35. package/docs/zh/guides/basic-features/render/before-render.mdx +115 -0
  36. package/docs/zh/guides/basic-features/routes.mdx +0 -95
  37. package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +3 -5
  38. package/docs/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +4 -2
  39. package/docs/zh/guides/topic-detail/model/auto-actions.mdx +0 -4
  40. package/docs/zh/guides/topic-detail/model/computed-state.mdx +0 -4
  41. package/docs/zh/guides/topic-detail/model/define-model.mdx +1 -4
  42. package/docs/zh/guides/topic-detail/model/faq.mdx +0 -5
  43. package/docs/zh/guides/topic-detail/model/manage-effects.mdx +0 -4
  44. package/docs/zh/guides/topic-detail/model/model-communicate.mdx +1 -4
  45. package/docs/zh/guides/topic-detail/model/performance.mdx +0 -4
  46. package/docs/zh/guides/topic-detail/model/quick-start.mdx +7 -8
  47. package/docs/zh/guides/topic-detail/model/redux-integration.mdx +0 -4
  48. package/docs/zh/guides/topic-detail/model/typescript-best-practice.mdx +0 -4
  49. package/docs/zh/guides/topic-detail/model/use-model.mdx +0 -5
  50. package/docs/zh/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -4
  51. package/package.json +1 -1
@@ -1,44 +1,30 @@
1
- ---
2
- title: App.[tj]sx
3
- sidebar_position: 1
4
- ---
5
1
  # App.[tj]sx
6
2
 
7
- The identifier for the entry points when the application uses [Self-controlled Routing](/guides/concept/entries.html#self-controlled-routing).
3
+ The entry identifier when using [Self-controlled Routing](/guides/concept/entries.html#self-controlled-routing) in the application.
8
4
 
9
- `App.[tj]sx` is not the actual entry. Modern.js will generate the real entry for application. The content is roughly as follows:
5
+ `App.[tj]sx` is not the actual application entry; Modern.js will automatically generate the real entry file, which is roughly as follows:
10
6
 
11
7
  ```js
12
- import React from 'react';
13
- import ReactDOM from 'react-dom/client';
14
- import { createApp, bootstrap } from '@modern-js/runtime';
15
- // App.[jt]sx
8
+ // runtime-global-context
9
+ import { setGlobalContext } from '@modern-js/runtime/context';
16
10
  import App from '@_modern_js_src/App';
17
- // runtime plugin
18
- import { router } from '@modern-js/runtime/plugins';
19
-
20
- const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
21
- const MOUNT_ID = 'root';
22
-
23
- let AppWrapper = null;
24
-
25
- function render() {
26
- AppWrapper = createApp({
27
- plugins: [
28
- router({...{"serverBase":["/"]}, ...App.config?.router}),
29
- ]
30
- })(App)
31
- if (IS_BROWSER) {
32
- bootstrap(AppWrapper, MOUNT_ID, null, ReactDOM);
33
- }
34
- return AppWrapper
35
- }
36
-
37
- AppWrapper = render();
38
- export default AppWrapper;
11
+
12
+ setGlobalContext({
13
+ App,
14
+ });
15
+
16
+ // index.tsx
17
+ import './runtime-global-context';
18
+ import { createRoot } from '@modern-js/runtime/react';
19
+ import { render } from '@modern-js/runtime/browser';
20
+
21
+ const ModernRoot = createRoot();
22
+
23
+ render(<ModernRoot />, 'root');
39
24
  ```
40
25
 
41
- :::note
42
- In the multi-entry scenario, each entry can have its own `App.[jt]sx`. See [Entries](/guides/concept/entries) for details.
26
+ When `createRoot` is executed, it will retrieve the registered Global App and generate the actual React component.
43
27
 
28
+ :::note
29
+ In scenarios with multiple entry points, each entry can have its own independent `App.[jt]sx`. For more details, see [Entry Points](/guides/concept/entries).
44
30
  :::
@@ -0,0 +1,9 @@
1
+ ---
2
+ title: modern.runtime.[tj]s
3
+ sidebar_position: 4
4
+ ---
5
+ # modern.runtime.[tj]s
6
+
7
+ The Modern.js Runtime configuration file allows for personalized configuration of the Runtime capabilities for the current project.
8
+
9
+ For specific usage of the configuration, please refer to [Runtime Configuration](/configure/app/runtime/0-intro.html).
@@ -3,8 +3,14 @@ title: defineConfig
3
3
  ---
4
4
  # defineConfig
5
5
 
6
+ :::warning
7
+
8
+ Soon to be deprecated. It is recommended to use `src/modern.runtime.ts` to define Runtime configurations, which supports both static and dynamic configurations. Please refer to the plugin [Runtime Configuration](/configure/app/runtime/0-intro.html).
9
+
6
10
  For dynamically configuring applications runtime features.
7
11
 
12
+ :::
13
+
8
14
  ## Usage
9
15
 
10
16
  ```ts
@@ -1,13 +1,30 @@
1
- ```js title="modern.config.ts"
1
+ ```ts title="modern.config.ts"
2
2
  import { appTools, defineConfig } from '@modern-js/app-tools';
3
3
  import { garfishPlugin } from '@modern-js/plugin-garfish';
4
4
 
5
5
  export default defineConfig({
6
6
  runtime: {
7
7
  router: true,
8
- state: true,
9
- masterApp: true,
10
8
  },
11
9
  plugins: [appTools(), garfishPlugin()],
12
10
  });
11
+
12
+ ```
13
+
14
+ ```ts title="src/modern.runtime.ts"
15
+ import { defineRuntimeConfig } from '@modern-js/runtime';
16
+
17
+ export default defineRuntimeConfig({
18
+ masterApp: {
19
+ apps: [{
20
+ name: 'Table',
21
+ entry: 'http://localhost:8081',
22
+ // activeWhen: '/table'
23
+ }, {
24
+ name: 'Dashboard',
25
+ entry: 'http://localhost:8082'
26
+ // activeWhen: '/dashboard'
27
+ }]
28
+ },
29
+ });
13
30
  ```
@@ -1,18 +1,17 @@
1
- ```js title="src/App.tsx"
2
- import { defineConfig } from '@modern-js/runtime';
1
+ ```ts title="src/modern.runtime.ts"
2
+ import { defineRuntimeConfig } from '@modern-js/runtime';
3
3
 
4
- defineConfig(App, {
4
+ export default defineRuntimeConfig({
5
5
  masterApp: {
6
- apps: [
7
- {
8
- name: 'DashBoard',
9
- entry: 'http://127.0.0.1:8081/',
10
- },
11
- {
12
- name: 'TableList',
13
- entry: 'http://localhost:8082',
14
- },
15
- ],
6
+ apps: [{
7
+ name: 'Table',
8
+ entry: 'http://localhost:8081',
9
+ // activeWhen: '/table'
10
+ }, {
11
+ name: 'Dashboard',
12
+ entry: 'http://localhost:8082'
13
+ // activeWhen: '/dashboard'
14
+ }]
16
15
  },
17
16
  });
18
17
  ```
@@ -0,0 +1,27 @@
1
+ :::warning
2
+ Starting from `MAJOR_VERSION.67.0`, Modern.js no longer provides Reduck state management capabilities by default. If you need to use Reduck, you must install and register the state plugin.
3
+
4
+ **Installation Steps**
5
+
6
+ 1. Install the `@modern-js/plugin-state` dependency:
7
+
8
+ ```bash
9
+ pnpm add @modern-js/plugin-state
10
+ ```
11
+
12
+ 2. Register the state plugin:
13
+
14
+ ```ts title="modern.config.ts"
15
+ import { defineConfig } from '@modern-js/app-tools';
16
+ import { statePlugin } from '@modern-js/plugin-state';
17
+
18
+ export default defineConfig({
19
+ ...,
20
+ plugins: [
21
+ ...,
22
+ statePlugin(),
23
+ ],
24
+ });
25
+ ```
26
+
27
+ :::
@@ -1,119 +1,91 @@
1
- ---
2
- title: Overview
3
- sidebar_position: 1
4
- ---
1
+ # Introduce
5
2
 
6
- # Overview
3
+ Modern.js runtime configuration should be centralized in the `src/modern.runtime.ts` file.
7
4
 
8
- This section describes configuration of the Runtime plugin.
9
-
10
- ## Configuration
11
-
12
- ### runtime
13
-
14
- - **Type:** `Object`
15
-
16
- The runtime is configured as follows:
5
+ :::info
6
+ If this file doesn't exist in your project yet, create it with the following command:
17
7
 
18
- #### Base
8
+ ```bash
9
+ touch src/modern.runtime.ts
10
+ ```
11
+ :::
19
12
 
20
- Configure in `modern.config.ts`:
13
+ ## Basic Configuration
21
14
 
22
- ```ts title="modern.config.ts"
23
- import { defineConfig } from '@modern-js/app-tools';
15
+ ```tsx
16
+ import { defineRuntimeConfig } from '@modern-js/runtime';
24
17
 
25
- export default defineConfig({
26
- runtime: {
27
- state: true,
28
- router: true,
18
+ export default defineRuntimeConfig({
19
+ router: {
20
+ // Router configuration
21
+ },
22
+ state: {
23
+ // State management configuration
29
24
  },
25
+ // Other runtime modules...
30
26
  });
31
27
  ```
32
28
 
33
- #### DefineConfig
34
-
35
- Configure using [`defineConfig`](/apis/app/runtime/app/define-config) API:
36
-
37
- :::info
38
- When there is a function in the runtime configuration, it can only be configured this way.
39
-
40
- :::
29
+ ## Multi-Entry Configuration
41
30
 
42
- import { Tabs, Tab as TabItem } from "@theme";
31
+ For multi-entry applications, `defineRuntimeConfig` can accept a function that returns specific configurations based on the entry name:
43
32
 
44
- <Tabs>
45
- <TabItem value="layout" label="Conventional Routing" default>
33
+ ```tsx
34
+ import { defineRuntimeConfig } from '@modern-js/runtime';
46
35
 
47
- ```tsx title="src/routes/layout.tsx"
48
- import type { AppConfig } from '@modern-js/runtime';
49
-
50
- export const config = (): AppConfig => {
51
- return {
52
- router: {
53
- supportHtml5History: false
54
- }
36
+ export default defineRuntimeConfig((entryName) => {
37
+ if (entryName === 'main') {
38
+ return {
39
+ router: {
40
+ // Router configuration for "main" entry
41
+ },
42
+ state: {
43
+ // State management configuration for "main" entry
44
+ },
45
+ };
55
46
  }
56
- };
57
- ```
58
-
59
- </TabItem>
60
-
61
- <TabItem value="app" label="Self-controlled Routing">
62
-
63
- ```ts title="src/App.tsx"
64
- import { defineConfig } from '@modern-js/runtime';
65
-
66
- const App = () => {
67
- /** */
68
- };
69
47
 
70
- defineConfig(App, {
71
- router: {
72
- supportHtml5History: false,
73
- },
48
+ // Configuration for other entries
49
+ return {
50
+ masterApp: {
51
+ // Micro-frontend configuration example
52
+ },
53
+ };
74
54
  });
75
-
76
- export default App;
77
55
  ```
78
-
79
- </TabItem>
80
- </Tabs>
81
-
82
- :::info
83
- Using runtime configuration, you can solve the problem that runtime plugin configuration needs to be at runtime to get specific content.
84
-
85
- Runtime plugin runtime configuration and configuration directly in `modern.config.ts` are merged by default, and runtime configuration takes precedence.
86
-
56
+ :::tip
57
+ Using the `src/modern.runtime.ts` configuration approach does not support exporting asynchronous functions, which is related to the rendering method of Modern.js. If you need to add asynchronous logic, please use the **[Runtime Plugin](/plugin/introduction.html#runtime-plugin)**.
87
58
  :::
88
59
 
89
60
  :::warning
90
- The `defineConfig` API only accepts the specific configuration of Runtime plugins. Enabling the plugin is determined through `modern.config.ts` configuration."
91
-
61
+ Using the `src/modern.runtime.ts` configuration approach requires Modern.js version **MAJOR_VERSION.66.0** or higher.
92
62
  :::
93
63
 
94
- ### runtimeByEntries
64
+ ## Configuration Evolution
95
65
 
96
- - **Type:** `Object`
66
+ Before MAJOR_VERSION.66.0, runtime configurations were scattered across multiple locations:
97
67
 
98
- #### Introduction
68
+ 1. The `runtime` and `runtimeByEntries` fields in `modern.config.ts`
69
+ 2. The `App.config` or the `config` function exported from `layout` files for each entry
99
70
 
100
- Add the runtime configuration according to the entry. The option attribute is consistent with the runtime. The specified value will be replaced and merged with the content of the runtime attribute.
71
+ To improve maintainability, Modern.js introduced the unified `src/modern.runtime.ts` configuration entry.
101
72
 
102
- ```ts title="modern.config.ts"
103
- import { defineConfig } from '@modern-js/app-tools';
73
+ ### Legacy Configuration (Compatible but Not Recommended)
104
74
 
105
- export default defineConfig({
106
- runtime: {
107
- state: false,
108
- },
109
- runtimeByEntries: {
110
- entry1: {
111
- state: true, // { state: true }
112
- },
113
- entry2: {
114
- // { state: false, router: true }
115
- router: true,
116
- },
117
- },
118
- });
75
+ ```ts
76
+ // modern.config.ts
77
+ export default {
78
+ runtime: { /* ... */ },
79
+ runtimeByEntries: { /* ... */ },
80
+ };
81
+
82
+ // App.config
83
+ App.config = {/* ... */}
84
+
85
+ // layout file
86
+ export const config = () => { /* Dynamic configuration logic */ };
119
87
  ```
88
+
89
+ ### Migration Recommendation
90
+
91
+ We strongly recommend migrating all runtime configurations to `src/modern.runtime.ts`. Although the legacy configuration approach is still compatible, it is planned to be gradually deprecated in future versions. A unified configuration entry prevents scattered configurations and significantly improves project maintainability.