@modern-js/main-doc 2.0.0-beta.3 → 2.0.0-beta.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/dev.md +8 -3
  3. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/inspect.md +31 -10
  4. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/serve.md +32 -0
  5. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/server.md +31 -0
  6. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/bootstrap.md +4 -3
  7. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/create-app.md +2 -3
  8. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/use-module-apps.md +1 -1
  9. package/en/docusaurus-plugin-content-docs/current/components/init-app.md +42 -0
  10. package/en/docusaurus-plugin-content-docs/current/configure/app/builder-plugins.md +70 -0
  11. package/en/docusaurus-plugin-content-docs/current/configure/app/dev/with-master-app.md +0 -1
  12. package/en/docusaurus-plugin-content-docs/current/configure/app/plugins.md +11 -5
  13. package/en/docusaurus-plugin-content-docs/current/configure/app/server/routes.md +2 -4
  14. package/en/docusaurus-plugin-content-docs/current/configure/app/source/disable-entry-dirs.md +38 -0
  15. package/en/docusaurus-plugin-content-docs/current/configure/app/source/entries.md +66 -2
  16. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/esbuild.md +16 -39
  17. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/css/css-in-js.md +38 -0
  18. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/css/css-modules.md +86 -0
  19. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/css/less-sass.md +17 -0
  20. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/css/postcss.md +81 -0
  21. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/css/tailwindcss.md +95 -0
  22. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/data-fetch.md +66 -0
  23. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/routes.md +270 -0
  24. package/en/docusaurus-plugin-content-docs/current/guides/concept/entries.md +116 -0
  25. package/en/docusaurus-plugin-content-docs/current/guides/get-started/quick-start.md +162 -0
  26. package/en/docusaurus-plugin-content-docs/current/guides/get-started/upgrade.md +78 -0
  27. package/{zh/tutorials/first-app → en/docusaurus-plugin-content-docs/current/guides}/overview.md +4 -4
  28. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/_category_.json +4 -0
  29. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/lifecycle.md +15 -0
  30. package/en/docusaurus-plugin-content-docs/current/tutorials/foundations/introduction.md +1 -1
  31. package/en/docusaurus-plugin-content-docs/current.json +11 -11
  32. package/package.json +4 -4
  33. package/zh/apis/app/commands/dev.md +9 -4
  34. package/zh/apis/app/commands/inspect.md +32 -11
  35. package/zh/apis/app/commands/new.md +1 -1
  36. package/zh/apis/app/commands/{start.md → serve.md} +3 -3
  37. package/zh/apis/app/hooks/src/index_.md +5 -4
  38. package/zh/apis/app/hooks/src/server.md +31 -0
  39. package/zh/apis/app/runtime/core/bootstrap.md +3 -4
  40. package/zh/apis/app/runtime/core/create-app.md +1 -18
  41. package/zh/apis/app/runtime/core/use-module-apps.md +64 -33
  42. package/zh/apis/app/runtime/web-server/hook.md +1 -1
  43. package/zh/apis/app/runtime/web-server/middleware.md +1 -0
  44. package/zh/components/debug-app.md +18 -0
  45. package/zh/components/default-mwa-generate.md +5 -0
  46. package/zh/components/deploy.md +1 -0
  47. package/zh/components/enable-micro-frontend.md +13 -0
  48. package/zh/components/global-proxy.md +28 -0
  49. package/zh/components/init-app.md +44 -0
  50. package/zh/components/micro-runtime-config.md +18 -0
  51. package/zh/components/prerequisites.md +19 -0
  52. package/zh/components/release-note.md +1 -0
  53. package/zh/configure/app/builder-plugins.md +72 -0
  54. package/zh/configure/app/deploy/_category_.json +4 -0
  55. package/zh/configure/app/deploy/microFrontend.md +64 -0
  56. package/zh/configure/app/dev/with-master-app.md +0 -2
  57. package/zh/configure/app/plugins.md +10 -4
  58. package/zh/configure/app/runtime/master-app.md +33 -36
  59. package/zh/configure/app/server/routes.md +2 -4
  60. package/zh/configure/app/source/disable-entry-dirs.md +37 -0
  61. package/zh/configure/app/source/entries-dir.md +0 -3
  62. package/zh/configure/app/source/entries.md +66 -3
  63. package/zh/configure/app/tools/esbuild.md +16 -39
  64. package/zh/guides/advanced-features/bff/bff-proxy.md +1 -1
  65. package/zh/guides/advanced-features/compatibility.md +14 -39
  66. package/zh/guides/advanced-features/eslint.md +21 -21
  67. package/zh/guides/advanced-features/ssg.md +20 -9
  68. package/zh/guides/advanced-features/ssr.md +95 -52
  69. package/zh/guides/advanced-features/testing.md +44 -1
  70. package/zh/guides/advanced-features/web-server.md +14 -3
  71. package/zh/guides/basic-features/css/tailwindcss.md +13 -6
  72. package/zh/guides/basic-features/data-fetch.md +398 -5
  73. package/zh/guides/basic-features/html.md +182 -0
  74. package/zh/guides/basic-features/mock.md +3 -9
  75. package/zh/guides/basic-features/proxy.md +2 -27
  76. package/zh/guides/basic-features/routes.md +35 -3
  77. package/zh/guides/concept/entries.md +108 -19
  78. package/zh/guides/get-started/quick-start.md +14 -83
  79. package/zh/guides/get-started/upgrade.md +11 -9
  80. package/zh/guides/{concept → topic-detail/framework-plugin}/lifecycle.md +0 -0
  81. package/zh/guides/topic-detail/micro-frontend/c01-introduction.md +29 -0
  82. package/zh/guides/topic-detail/micro-frontend/c02-development.md +191 -0
  83. package/zh/guides/topic-detail/micro-frontend/c03-main-app.md +246 -0
  84. package/zh/guides/topic-detail/micro-frontend/c04-communicate.md +54 -0
  85. package/zh/guides/topic-detail/micro-frontend/{mixed-stack.md → c05-mixed-stack.md} +3 -3
  86. package/zh/guides/topic-detail/model/quick-start.md +1 -1
  87. package/zh/guides/topic-detail/model/test-model.md +2 -2
  88. package/zh/guides/topic-detail/monorepo/create-sub-project.md +2 -2
  89. package/zh/guides/topic-detail/monorepo/intro.md +1 -1
  90. package/zh/guides/troubleshooting/dependencies.md +0 -69
  91. package/zh/tutorials/first-app/_category_.json +1 -1
  92. package/zh/tutorials/first-app/c01-start.md +99 -0
  93. package/zh/tutorials/first-app/{c05-component/5.1-use-ui-library.md → c02-component.md} +13 -15
  94. package/zh/tutorials/first-app/c03-css.md +324 -0
  95. package/zh/tutorials/first-app/{c08-client-side-routing/8.1-code-based-routing.md → c04-routes.md} +52 -39
  96. package/zh/tutorials/first-app/c05-loader.md +82 -0
  97. package/zh/tutorials/first-app/c06-model.md +256 -0
  98. package/zh/tutorials/first-app/c07-container.md +283 -0
  99. package/zh/tutorials/first-app/c08-entries.md +137 -0
  100. package/zh/tutorials/foundations/introduction.md +1 -1
  101. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/start.md +0 -32
  102. package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-modern-mode.md +0 -34
  103. package/zh/apis/generator/overview.md +0 -32
  104. package/zh/configure/app/output/enable-modern-mode.md +0 -34
  105. package/zh/guides/advanced-features/custom-app.md +0 -72
  106. package/zh/guides/topic-detail/micro-frontend/communicate.md +0 -39
  107. package/zh/guides/topic-detail/micro-frontend/debugging.md +0 -168
  108. package/zh/guides/topic-detail/micro-frontend/introduction.md +0 -13
  109. package/zh/guides/topic-detail/micro-frontend/route-mode.md +0 -110
  110. package/zh/guides/topic-detail/monorepo/deploy.md +0 -43
  111. package/zh/tutorials/first-app/c01-getting-started/1.1-prerequisites.md +0 -25
  112. package/zh/tutorials/first-app/c01-getting-started/1.2-minimal-mwa.md +0 -118
  113. package/zh/tutorials/first-app/c01-getting-started/1.3-dev-command.md +0 -29
  114. package/zh/tutorials/first-app/c01-getting-started/1.4-enable-ssr.md +0 -47
  115. package/zh/tutorials/first-app/c01-getting-started/1.5-start-command.md +0 -18
  116. package/zh/tutorials/first-app/c01-getting-started/1.6-create-repo.md +0 -31
  117. package/zh/tutorials/first-app/c01-getting-started/_category_.json +0 -3
  118. package/zh/tutorials/first-app/c02-generator-and-studio/2.1-generator.md +0 -79
  119. package/zh/tutorials/first-app/c02-generator-and-studio/2.2-boilerplates.md +0 -34
  120. package/zh/tutorials/first-app/c02-generator-and-studio/2.3-configuration.md +0 -19
  121. package/zh/tutorials/first-app/c02-generator-and-studio/_category_.json +0 -3
  122. package/zh/tutorials/first-app/c03-ide/3.1-setting-up.md +0 -55
  123. package/zh/tutorials/first-app/c03-ide/3.2-hints-in-ide.md +0 -60
  124. package/zh/tutorials/first-app/c03-ide/3.3-autofix-in-ide.md +0 -11
  125. package/zh/tutorials/first-app/c03-ide/3.4-autofix-in-cli.md +0 -63
  126. package/zh/tutorials/first-app/c03-ide/_category_.json +0 -3
  127. package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.1-use-es6-plus.md +0 -54
  128. package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.2-use-typescript.md +0 -135
  129. package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.3-compatibility.md +0 -67
  130. package/zh/tutorials/first-app/c04-es6-plus-and-ts/_category_.json +0 -3
  131. package/zh/tutorials/first-app/c05-component/5.2-use-standalone-component.md +0 -72
  132. package/zh/tutorials/first-app/c05-component/_category_.json +0 -3
  133. package/zh/tutorials/first-app/c06-css-and-component/6.1-css-in-js.md +0 -110
  134. package/zh/tutorials/first-app/c06-css-and-component/6.2-utility-class.md +0 -143
  135. package/zh/tutorials/first-app/c06-css-and-component/6.3-postcss.md +0 -84
  136. package/zh/tutorials/first-app/c06-css-and-component/6.4-design-system.md +0 -83
  137. package/zh/tutorials/first-app/c06-css-and-component/6.5-storybook.md +0 -77
  138. package/zh/tutorials/first-app/c06-css-and-component/6.6-testing.md +0 -104
  139. package/zh/tutorials/first-app/c06-css-and-component/_category_.json +0 -3
  140. package/zh/tutorials/first-app/c07-app-entry/7.1-intro.md +0 -69
  141. package/zh/tutorials/first-app/c07-app-entry/7.2-add-entry-in-cli.md +0 -100
  142. package/zh/tutorials/first-app/c07-app-entry/7.3-manage-entries-by-hand.md +0 -69
  143. package/zh/tutorials/first-app/c07-app-entry/_category_.json +0 -3
  144. package/zh/tutorials/first-app/c08-client-side-routing/_category_.json +0 -3
  145. package/zh/tutorials/first-app/c09-bff/9.1-serverless.md +0 -30
  146. package/zh/tutorials/first-app/c09-bff/9.2-enable-bff.md +0 -95
  147. package/zh/tutorials/first-app/c09-bff/9.3-fetch-bff.md +0 -131
  148. package/zh/tutorials/first-app/c09-bff/_category_.json +0 -3
  149. package/zh/tutorials/first-app/c10-model/10.1-application-architecture.md +0 -21
  150. package/zh/tutorials/first-app/c10-model/10.2-add-model.md +0 -185
  151. package/zh/tutorials/first-app/c10-model/10.3-use-model.md +0 -55
  152. package/zh/tutorials/first-app/c10-model/10.4-testing.md +0 -69
  153. package/zh/tutorials/first-app/c10-model/_category_.json +0 -3
  154. package/zh/tutorials/first-app/c11-container/11.1-use-model-with-app-state.md +0 -240
  155. package/zh/tutorials/first-app/c11-container/11.2-add-container.md +0 -109
  156. package/zh/tutorials/first-app/c11-container/11.3-use-loader.md +0 -63
  157. package/zh/tutorials/first-app/c11-container/11.4-testing.md +0 -56
  158. package/zh/tutorials/first-app/c11-container/_category_.json +0 -3
@@ -1,4 +1,4 @@
1
1
 
2
- > @modern-js/main-doc@2.0.0-beta.3 build /github/workspace/packages/toolkit/main-doc
2
+ > @modern-js/main-doc@2.0.0-beta.4 build /Users/bytedance/github/modern.js/packages/toolkit/main-doc
3
3
  > npx ts-node ./scripts/sync.ts
4
4
 
@@ -2,10 +2,10 @@
2
2
  sidebar_position: 1
3
3
  ---
4
4
 
5
- # dev
5
+ # dev / start
6
6
 
7
7
  ```bash
8
- Usage: modern dev [options]
8
+ Usage: modern dev / modern start [options]
9
9
 
10
10
  Development commands
11
11
 
@@ -19,8 +19,13 @@ Options:
19
19
 
20
20
  `modern dev` start a development server,watch file change,default support React Fast Refresh:
21
21
 
22
+ `modern start` is an alias of `modern dev` command, the usage of the two are exactly the same.
23
+
22
24
  ```bash
23
- App running at:
25
+ $ modern dev
26
+
27
+ info Starting dev server...
28
+ info App running at:
24
29
 
25
30
  > Local: http://localhost:8080/
26
31
  > Network: http://192.168.0.1:8080/
@@ -5,35 +5,56 @@ sidebar_position: 7
5
5
  ```
6
6
  Usage: modern inspect [options]
7
7
 
8
- inspect internal webpack config
9
-
10
8
  Options:
11
9
  --env <env> view the configuration in the target environment (default: "development")
12
10
  --output <output> Specify the path to output in the dist (default: "/")
13
- --no-console Do not output the full result in shell
14
11
  --verbose Show the full function in the result
15
12
  -c --config <config> configuration file path, which can be a relative path or an absolute path
16
13
  -h, --help show command help
17
14
  ```
18
15
 
19
- `modern inspect` command used to view the full webpack configuration of the project.
16
+ `modern inspect` command used to view the [Modern.js Builder config](https://modernjs.dev/builder/en/guide/basic/builder-config.html) and webpack config of the project.
17
+
18
+ After executing the command `npx modern inspect` in the project root directory, the following files will be generated in the `dist` directory of the project:
20
19
 
21
- Executing the command `npx modern inspect` in the project will output the webpack configuration on the shell, and will also generate a `webpack.client.inspect.js` file in the project's `dist` directory, which developers can open and view manually.
20
+ - `builder.config.js`: The Modern.js Builder config to use at build time.
21
+ - `webpack.config.web.js`: The webpack config used by to use at build time.
22
+
23
+ ```bash
24
+ ➜ npx modern inspect
25
+
26
+ Inspect config succeed, open following files to view the content:
27
+
28
+ - Builder Config: /root/my-project/dist/builder.config.js
29
+ - Webpack Config (web): /root/my-project/dist/webpack.config.web.js
30
+ ```
22
31
 
23
32
  ## Configuration Env
24
33
 
25
- By default, the webpack configuration of the development environment is output. And the `env` option can be used to output the configuration of the production environment:
34
+ By default, the inspect command will output the development configs, you can use the `--env production` option to output the production configs:
26
35
 
27
36
  ```bash
28
37
  modern inspect --env production
29
38
  ```
30
39
 
31
- ## Configuration Type
40
+ ## Verbose content
41
+
42
+ By default, the inspect command will omit the function content in the config object, you can use the `--verbose` option to output the full content of the function:
43
+
44
+ ```bash
45
+ modern inspect --verbose
46
+ ```
32
47
 
33
48
  ### SSR Configuration
34
49
 
35
- If the project has SSR enable, an additional `webpack.ssr.inspect.js` file will be generated in the `dist/`, corresponding to the webpack configuration at SSR build time.
50
+ If the project has enabled SSR, an additional `webpack.config.node.js` file will be generated in the `dist/`, corresponding to the webpack configuration at SSR build time.
36
51
 
37
- ### Modern Configuration
52
+ ```bash
53
+ ➜ npx modern inspect
54
+
55
+ Inspect config succeed, open following files to view the content:
38
56
 
39
- if project enable [enableModernMode](/docs/configure/app/output/enable-modern-mode), an additional `webpack.modern.inspect.js` file will be generated in the `dist/`corresponding to the webpack configuration at modern web build.
57
+ - Builder Config: /root/my-project/dist/builder.config.js
58
+ - Webpack Config (web): /root/my-project/dist/webpack.config.web.js
59
+ - Webpack Config (node): /root/my-project/dist/webpack.config.node.js
60
+ ```
@@ -0,0 +1,32 @@
1
+ ---
2
+ sidebar_position: 6
3
+ ---
4
+
5
+ ```bash
6
+ Usage: modern serve [options]
7
+
8
+ run server
9
+
10
+ Options:
11
+ -c --config <config> configuration file path, which can be a relative path or an absolute path
12
+ -h, --help show command help
13
+ --api-only only run API service
14
+ ```
15
+
16
+ Usually use the `modern serve` command to enable project run in the production environment, and you need to execute the [`build'](/docs/apis/app/commands/build) command in advance to build the product.
17
+
18
+ By default, the project will run in `localhost:8080`, you can modify the Server port number with `server.port`:
19
+
20
+ ```js
21
+ export default defineConfig({
22
+ server: {
23
+ port: 8081,
24
+ }
25
+ })
26
+ ```
27
+
28
+ import CommandTip from '@site-docs-en/components/command-tip.md'
29
+
30
+ <CommandTip />
31
+
32
+
@@ -0,0 +1,31 @@
1
+ ---
2
+ title: "*.[server|node].[tj]sx"
3
+ sidebar_position: 8
4
+ ---
5
+
6
+ Used in application projects to place server side code, it generally has the following two functions:
7
+
8
+ 1. When `*.tsx` and `*. [server|node].tsx` coexist, rendering on the server side will give preference to the `*. [server|node].tsx` file instead of the `*.tsx` file.
9
+
10
+ 2. When using [data loader](/docs/guides/basic-features/data-fetch), the server-side dependencies need to be re-exported from this file
11
+
12
+ ```tsx
13
+ // routes/user/avatar.tsx
14
+ import { useLoaderData } from '@modern-js/runtime/router';
15
+ import { readFile } from './utils.server';
16
+
17
+ type ProfileData = { /* some type declarations */ }
18
+
19
+ export const loader = async(): ProfileData => {
20
+ const profile = await readFile('profile.json');
21
+ return profile;
22
+ }
23
+
24
+ export default function UserPage() {
25
+ const profileData = useLoaderData() as ProfileData;
26
+ return <div>{profileData}</div>;
27
+ }
28
+
29
+ // routes/user/utils.server.ts
30
+ export * from 'fs-extra';
31
+ ```
@@ -2,7 +2,7 @@
2
2
  title: bootstrap
3
3
  ---
4
4
 
5
- Used to start and mount App, usually without manual calls。This API is only required when using [Custom App](/docs/guides/advanced-features/custom-app).
5
+ Used to start and mount App, usually without manual calls。This API is only required when using [Custom App](/docs/guides/concept/entries#自定义-app).
6
6
 
7
7
  ## Usage
8
8
 
@@ -41,7 +41,6 @@ type BootStrap<T = unknown> = (
41
41
  ```tsx
42
42
  import ReactDOM from 'react-dom/client'
43
43
  import { createApp, bootstrap } from '@modern-js/runtime';
44
- import { router, state } from '@modern-js/runtime/plugins';
45
44
 
46
45
  function App() {
47
46
  return <div>Hello Modern.js</div>;
@@ -49,7 +48,9 @@ function App() {
49
48
 
50
49
  const WrappedApp = createApp({
51
50
  // customized plugin
52
- plugins: [router({}), state({})],
51
+ plugins: [
52
+ customPlugin(),
53
+ ],
53
54
  })(App);
54
55
 
55
56
  bootstrap(WrappedApp, 'root', undefined, ReactDOM);
@@ -2,7 +2,7 @@
2
2
  title: createApp
3
3
  ---
4
4
 
5
- Used to create custom entries, custom runtime plugins. This API is only required when using [Custom App](/docs/guides/advanced-features/custom-app).
5
+ Used to create custom entries, custom runtime plugins. This API is only required when using [Custom App](/docs/guides/concept/entries#自定义-app).
6
6
 
7
7
  ## Usage
8
8
 
@@ -40,8 +40,7 @@ function App() {
40
40
 
41
41
  export default createApp({
42
42
  plugins: [
43
- router({}),
44
- state({}),
43
+ customPlugin()
45
44
  ]
46
45
  })(App);
47
46
  ```
@@ -7,7 +7,7 @@ Returns the React components of all micro-front-end sub-applications for freely
7
7
  ## Usage
8
8
 
9
9
  ```tsx
10
- import { useModuleApps } from '@modern/plugin-garfish';
10
+ import { useModuleApps } from '@modern-js/runtime/garfish';
11
11
  ```
12
12
 
13
13
  :::info Turn on
@@ -0,0 +1,42 @@
1
+ Modern.js generator will provide an interactive Q & A interface, initialization items according to the result, according to the default selection:
2
+
3
+ ```bash
4
+ ? Please select the solution you want to create: MWA Solution
5
+ ? Development Language: TS
6
+ ? Package Management Tool: pnpm
7
+ ```
8
+
9
+ After create the project, Modern.js automatically installs dependency and creates a git repository.
10
+
11
+ ```bash
12
+ [INFO] dependencies are automatically installed
13
+ [INFO] git repository has been automatically created
14
+ [INFO] Success!
15
+ You can run the following command in the directory of the new project:
16
+ pnpm run dev # Run and debug the project according to the requirements of the development environment
17
+ pnpm run build # Build the project according to the requirements of the product environment
18
+ pnpm run serve # Run the project according to the requirements of the product environment
19
+ pnpm run lint # Check and fix all codes
20
+ pnpm run new # Create more project elements, such as application portals
21
+ ```
22
+
23
+ :::note
24
+ In addition to working during project initialization, the Modern.js generator can also generate modules of the project in subsequent development, which is not thrown away as soon as it is used.
25
+ :::
26
+
27
+ Now, the project structure is as follows:
28
+
29
+ ```
30
+ .
31
+ ├── src
32
+ │   ├── modern-app-env.d.ts
33
+ │   └── routes
34
+ │   ├── index.css
35
+ │   ├── layout.tsx
36
+ │   └── page.tsx
37
+ ├── modern.config.ts
38
+ ├── package.json
39
+ ├── pnpm-lock.yaml
40
+ ├── README.md
41
+ └── tsconfig.json
42
+ ```
@@ -0,0 +1,70 @@
1
+ ---
2
+ title: builderPlugins
3
+ sidebar_position: 10
4
+ ---
5
+
6
+ - Type: `BuilderPlugin[]`
7
+ - Default: `[]`
8
+
9
+ Used to configure the Modern.js Builder plugin.
10
+
11
+ Modern.js Builder is the build engine of Modern.js, please read [Builder](/docs/guides/basic-features/builder) for background. If you want to know how to write Builder plugins, you can refer to [Modern.js Builder - Introduce to Plugin](https://modernjs.dev/builder/en/plugins/introduction.html).
12
+
13
+ ## Precautions
14
+
15
+ This option **is used to configure the Modern.js Builder plugins**. If you need to configure other types of plugins, please select the corresponding configs:
16
+
17
+ - Use [plugins](docs/configure/app/builder-plugins) to configure Modern.js framework plugins.
18
+ - Use [tools.webpack](/docs/configure/app/tools/webpack) or [tools.webpackChain](/docs/configure/app/tools/webpack-chain) to configure webpack plugins.
19
+ - Use [tools.babel](/docs/configure/app/tools/babel) to configure babel plugins.
20
+
21
+ ## When to use
22
+
23
+ In most scenarios, we recommend you to use the Modern.js framework plugin, which can be registered through the [plugins](docs/configure/app/plugins) config. Because the API provided by the framework plugin is richer and more capable, while the API provided by the Builder plugin can only be used to build scenes.
24
+
25
+ When you need to reference some existing Builder plugins (and there is no related capability in Modern.js), or reuse Builder plugins between different frameworks, you can use the `builderPlugins` field to register them.
26
+
27
+ ## Example
28
+
29
+ Below is an example of using the Builder plugin.
30
+
31
+ ### Using plugins on npm
32
+
33
+ To use a plugin on npm, you need to install the plugin through the package manager and import it.
34
+
35
+ ```ts title="modern.config.ts"
36
+ import MyBuilderPlugin from 'my-builder-plugin';
37
+
38
+ export default defineConfig({
39
+ builderPlugins: [MyBuilderPlugin()],
40
+ });
41
+ ```
42
+
43
+ ### Using local plugins
44
+
45
+ Use the plugin in the local code repository, you can import it directly through the relative path import.
46
+
47
+ ```ts title="modern.config.ts"
48
+ import MyBuilderPlugin from './plugin/myBuilderPlugin';
49
+
50
+ export default defineConfig({
51
+ builderPlugins: [MyBuilderPlugin()],
52
+ });
53
+ ```
54
+
55
+ ### Plugin configuration items
56
+
57
+ If the plugin provides some custom configuration options, you can pass in the configuration through the parameters of the plugin function.
58
+
59
+ ```ts title="modern.config.ts"
60
+ import MyBuilderPlugin from 'my-builder-plugin';
61
+
62
+ export default defineConfig({
63
+ builderPlugins: [
64
+ MyBuilderPlugin({
65
+ foo: 1,
66
+ bar: 2,
67
+ }),
68
+ ],
69
+ });
70
+ ```
@@ -29,4 +29,3 @@ export default defineConfig({
29
29
  - moduleApp: `string` Online address of the main application.
30
30
  - moduleName: `Contact` The name of the child app (needs to match the module name registered in the main app)。
31
31
 
32
- For detailed usage, please refer to [Micro Front-end Sub-Application](/docs/guides/topic-detail/micro-frontend/debugging)。
@@ -3,18 +3,24 @@ title: plugins
3
3
  sidebar_position: 9
4
4
  ---
5
5
 
6
- * Type: `CliPlugin[]`
7
- * Default: `[]`
6
+ - Type: `CliPlugin[]`
7
+ - Default: `[]`
8
8
 
9
- Used to configure custom Modern.js plugins.
9
+ Used to configure custom Modern.js framework plugins.
10
10
 
11
11
  For the way to write custom plugins, please refer to [How to Write Plugins](/docs/guides/topic-detail/framework-plugin/implement).
12
12
 
13
- This option is used to configure the framework plugin. If you need to configure the webpack plugin, please use [tools.webpack](/docs/configure/app/tools/webpack) or [tools.webpack Chain](/docs/configure/app/tools/webpack-chain); If you need to configure the babel plugin, please use [tools.babel](/docs/configure/app/tools/babel).
13
+ ## Precautions
14
+
15
+ This config **is used to configure the Modern.js framework plugin**. If you need to configure other types of plugins, please select the corresponding configs:
16
+
17
+ - Use [builderPlugins](docs/configure/app/builder-plugins) to configure Modern.js Builder plugins.
18
+ - Use [tools.webpack](/docs/configure/app/tools/webpack) or [tools.webpackChain](/docs/configure/app/tools/webpack-chain) to configure webpack plugins.
19
+ - Use [tools.babel](/docs/configure/app/tools/babel) to configure babel plugins.
14
20
 
15
21
  ## Plugin type
16
22
 
17
- There are three different plug-in mechanisms built into the Modern.js:
23
+ There are three different type of framework plugins built into the Modern.js:
18
24
 
19
25
  - `CLI Plugin`,for local development, compilation and build phases, can extend various capabilities on the command line and compilation phases.
20
26
  - `Server Plugin`,for server-level.
@@ -52,16 +52,14 @@ After executing the `dev` command, you can see in `dist/route.json` that there a
52
52
  "entryName": "page-a",
53
53
  "entryPath": "html/page-a/index.html",
54
54
  "isSPA": true,
55
- "isSSR": false,
56
- "enableModernMode": false
55
+ "isSSR": false
57
56
  },
58
57
  {
59
58
  "urlPath": "/b",
60
59
  "entryName": "page-a",
61
60
  "entryPath": "html/page-a/index.html",
62
61
  "isSPA": true,
63
- "isSSR": false,
64
- "enableModernMode": false
62
+ "isSSR": false
65
63
  },
66
64
  ]
67
65
  }
@@ -0,0 +1,38 @@
1
+ ---
2
+ title: source.disableEntryDirs
3
+
4
+ sidebar_label: disableEntryDirs
5
+ ---
6
+
7
+ * Type: `string[]`
8
+ * Default: `[]`
9
+
10
+ By default, application entries are identified based on the'src 'directory, you can disable some directories from being identified as application entries with this option.
11
+
12
+ For example, when the configuration and directory structure is as follows:
13
+
14
+
15
+ ```typescript title="modern.config.ts"
16
+ export default defineConfig({
17
+ source: {
18
+ disableEntryDirs: './src/one'
19
+ }
20
+ })
21
+ ```
22
+
23
+ ``` title="Project directory structure"
24
+ └── src/
25
+ ├── one/
26
+ | └── App.tsx
27
+ ├── two/
28
+ | └── routes/
29
+ └── env.d.ts
30
+ ```
31
+
32
+ When this option is not set, Modern.js will generate two entries based on the project directory:
33
+ - one
34
+ - two
35
+
36
+ When this option is set, `src/one` will not be recognized as an entry directory.
37
+
38
+ A common usage is to configure the `src/common`, `src/components` directories to this option to avoid these directories being recognized as application entries.
@@ -27,10 +27,34 @@ export default defineConfig({
27
27
  });
28
28
  ```
29
29
 
30
- Customized entry, only need to export `App` by default, Modern.js will generate a real entry file.
30
+ By default, the configured entry is equivalent to `App.[jt]sx`, that is, the specified entry file only needs to export the root component of the application.
31
31
 
32
- When this behavior needs to be turned off, the value can be set to `Object` and the property `disableMount` can be set to `true`.
32
+ For example the following directory structure:
33
33
 
34
+ ```bash
35
+ .
36
+ ├── src
37
+ │ └── entry
38
+ │ ├── chat.tsx
39
+ │ └── home.tsx
40
+ └── package.json
41
+ ```
42
+
43
+ With the content of the above default entry mechanism, Modern.js when analyzing the above directory, will not get any default entry.
44
+
45
+ In cases where you do not want to change the directory structure (such as project migration), you can customize the entry through `source.entries`:
46
+
47
+
48
+ ```ts title="modern.config.js"
49
+ export default defineConfig({
50
+ source: {
51
+ entries: {
52
+ home: './src/entry/home.tsx',
53
+ chat: './src/entry/chat.tsx',
54
+ },
55
+ },
56
+ });
57
+ ```
34
58
 
35
59
  ## Object
36
60
 
@@ -60,3 +84,43 @@ export default defineConfig({
60
84
  },
61
85
  });
62
86
  ```
87
+
88
+ By default, the configured entry is equivalent to `App.[jt]sx`. If you want the entry to be equivalent to the entry in build mode, you can set the value to'Object' and the property `disableMount` to `true`.
89
+
90
+ ## Combine Entry
91
+
92
+ When `source.entries` is specified, the Modern.js merges the user-defined entry with the default entry obtained by analyzing the directory structure. The merging rule is:
93
+
94
+ Compare the entry path set by the custom entry with the default entry path. When the entry paths are the same, the custom entry will override the default entry.
95
+
96
+ For example the following directory structure:
97
+
98
+
99
+ ```bash
100
+ .
101
+ ├── src
102
+ │ ├── chat
103
+ │ │ └── App.jsx
104
+ │ └── home
105
+ │ └── index.js
106
+ └── package.json
107
+ ```
108
+
109
+ Modern.js analyze the `src/` directory to get the default entries `chat` and `home`. When the user configures the following in the `modern.config.js` file:
110
+
111
+ ```ts title="modern.config.ts"
112
+ import { defineConfig } from '@modern-js/app-tools';
113
+
114
+ export default defineConfig({
115
+ source: {
116
+ entries: {
117
+ index: './src/home/index.js',
118
+ },
119
+ },
120
+ };
121
+ ```
122
+
123
+ You can see that the path of the custom entry `index` is the same as the path of the default entry `home`. During the merging process, `index` will override `home`, and the final entry is as follows:
124
+
125
+ - `chat -> ./src/chat/App.jsx`
126
+ - `index -> ./src/home/index.js`
@@ -3,59 +3,36 @@ title: tools.esbuild
3
3
  sidebar_label: esbuild
4
4
  ---
5
5
 
6
- * Type: `Object`
7
- * Default: `undefined`
6
+ - Type: `Object`
7
+ - Default: `undefined`
8
8
 
9
9
  ## Introduction
10
10
 
11
- Esbuild is a JavaScript Bundler/Minifier written in Go language, which is characterized by extremely fast speed. In terms of code compression, esbuild has dozens of times the performance improvement compared to webpack's built-in terser compressor.
12
-
13
- Modern.js provides the ability to compile and compress code based on esbuild. After opening it in a large project, ** can greatly reduce the time required for code compression, while effectively avoiding OOM (heap out of memory) problems **.
14
-
15
- Although the use of esbuild compression has brought about an improvement in construction efficiency, the compression ratio of esbuild is lower than that of terser, so the size of the ** bundle will increase **, please use it according to the business situation (more suitable for middle and back-end scenarios).
16
-
17
- For a detailed comparison between compression tools, see [mining-benchmarks](https://github.com/privatenumber/minification-benchmarks).
18
-
19
- :::info
20
- In addition to code compression, esbuild can also replace babel for code compilation. The advantage is that it can improve the compilation speed, but the disadvantage is that it cannot use the rich babel plug-in capabilities.
11
+ :::tip About esbuild
12
+ [esbuild](https://esbuild.github.io/) is a front-end build tool based on Golang. It has the functions of bundling, compiling and minimizing JavaScript code. Compared with traditional tools, the performance is significantly improved. When minimizing code, compared to webpack's built-in terser minimizer, esbuild has dozens of times better performance.
21
13
  :::
22
14
 
23
- ## Configuration
24
-
25
- ### target
15
+ Modern.js provides esbuild plugin that allow you to use esbuild instead of babel-loader, ts-loader and terser for transformation and minification process.
26
16
 
27
- * Type: `string | string[]`
28
- * Default `'esnext'`
29
-
30
- Set the target environment for the generated JavaScript and CSS code.
31
-
32
- Can be set directly to the JavaScript language version, such as `es5`, `es6`, `es2020`. It can also be set to several target environments, each target environment is an environment name followed by a version number. For example: `['chrome58', 'edge16', 'firefox57']`.
33
-
34
- The following environments are supported:
17
+ ## Configuration
35
18
 
36
- - chrome
37
- - edge
38
- - firefox
39
- - ie
40
- - ios
41
- - node
42
- - opera
43
- - safari
19
+ You can set the esbuild compilation behavior through the `tools.esbuild` config.
44
20
 
45
- By default, ES6 code, such as template string, is introduced into the esbuild compression process. If you need to be ES5 compatible, you can set `target` to `es5`.
21
+ ```js title="modern.config.ts"
22
+ import { defineConfig } from '@modern-js/app-tools';
46
23
 
47
- ```typescript title="modern.config.ts"
48
24
  export default defineConfig({
49
25
  tools: {
50
26
  esbuild: {
51
- target: 'es5',
27
+ loader: {
28
+ target: 'chrome61',
29
+ },
30
+ minimize: {
31
+ target: 'chrome61',
32
+ },
52
33
  },
53
34
  },
54
35
  });
55
36
  ```
56
37
 
57
- :::info
58
- When setting `target` to `es5`, you need to ensure that all code is escaped to es5 code by babel, otherwise it will cause an esbuild compilation error: `Transforming 'xxx' to the configured target environment ("es5") is not supported yet`.
59
-
60
- A detailed description of the `target` field can be found in [esbuild-target](https://esbuild.github.io/api/#target).
61
- :::
38
+ For config details, please refer to [Modern.js Builder - Esbuild Plugin Configuration](https://modernjs.dev/builder/en/plugins/plugin-esbuild.html#config).
@@ -0,0 +1,38 @@
1
+ ---
2
+ sidebar_position: 1
3
+ ---
4
+
5
+ # CSS-in-JS
6
+
7
+ CSS-in-JS is a technology that can write CSS styles in JS files. Modern.js integrates the CSS-in-JS library [styled-components](https://styled-components.com/) commonly used in the community, which uses the new feature of JavaScript [Tagged template](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) to write CSS styles for components. You can use the [styled-components](https://styled-components.com/) API directly from `@modern-js/runtime/styled`.
8
+
9
+ When you need to write a `div` component with an internal font in red, you can do the following implementation:
10
+
11
+ ```js
12
+ import styled from '@modern-js/runtime/styled'
13
+
14
+ const RedDiv = styled.div`
15
+ color: red;
16
+ `
17
+ ```
18
+
19
+ When you need to dynamically set the component style according to the `props` of the component, for example, when the attribute `primary` of `props` is `true`, the color of the button is white, and otherwise it is red. The implementation code is as follows:
20
+
21
+ ```js
22
+ import styled from '@modern-js/runtime/styled'
23
+
24
+ const Button = styled.button`
25
+ color: ${props => props.primary ? "white" : "red"};
26
+ font-size: 1em;
27
+ `
28
+ ```
29
+
30
+ For more usage of styled-components, please refer to [[styled-components official website](https://styled-components.com/) ].
31
+
32
+ :::info Additional
33
+ Modern.js uses the Babel plugin [babel-plugin-styled-components](https://github.com/styled-components/babel-plugin-styled-components) internally, and the plugin can be configured through [`tools.styled Components`](/docs/configure/app/tools/styled-components).
34
+ :::
35
+
36
+ :::tip
37
+ If you need to use [styled-jsx](https://www.npmjs.com/package/styled-jsx), [Emotion](https://emotion.sh/) and other CSS-in-JS libraries, you need to install the dependency of the corresponding library first. For specific usage, please refer to the official website of the corresponding library.
38
+ :::