@modern-js/main-doc 2.4.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +1 -1
- package/LICENSE +0 -123
- package/README.md +26 -0
- package/en/apis/app/commands.mdx +297 -0
- package/en/apis/app/hooks/_category_.json +2 -5
- package/en/apis/app/hooks/api/framework/lambda.mdx +1 -1
- package/en/apis/app/hooks/api/functions/api.mdx +1 -1
- package/en/apis/app/hooks/server/index_.mdx +2 -1
- package/en/apis/app/hooks/src/pages.mdx +7 -7
- package/en/apis/app/hooks/src/routes.mdx +3 -3
- package/en/apis/app/runtime/_category_.json +1 -5
- package/en/apis/app/runtime/app/define-config.mdx +2 -2
- package/en/apis/app/runtime/core/bootstrap.mdx +1 -1
- package/en/apis/app/runtime/core/create-app.mdx +2 -2
- package/en/apis/app/runtime/core/use-loader.mdx +4 -4
- package/en/apis/app/runtime/core/use-module-apps.mdx +2 -2
- package/en/apis/app/runtime/model/Provider.mdx +2 -2
- package/en/apis/app/runtime/model/auto-actions.mdx +2 -2
- package/en/apis/app/runtime/model/connect.mdx +5 -5
- package/en/apis/app/runtime/model/create-app.mdx +9 -9
- package/en/apis/app/runtime/model/create-store.mdx +3 -3
- package/en/apis/app/runtime/model/handle-effect.mdx +2 -2
- package/en/apis/app/runtime/model/model_.mdx +1 -1
- package/en/apis/app/runtime/model/use-local-model.mdx +1 -1
- package/en/apis/app/runtime/model/use-model.mdx +1 -1
- package/en/apis/app/runtime/model/use-static-model.mdx +4 -4
- package/en/apis/app/runtime/model/use-store.mdx +1 -1
- package/en/apis/app/runtime/router/router.mdx +1 -1
- package/en/apis/app/runtime/ssr/pre-render.mdx +1 -1
- package/en/apis/app/runtime/testing/render.mdx +1 -1
- package/en/apis/app/runtime/testing/renderApp.mdx +1 -1
- package/en/apis/app/runtime/utility/css-in-js.mdx +1 -1
- package/en/apis/app/runtime/utility/loadable.mdx +1 -1
- package/en/apis/app/runtime/web-server/hook.mdx +5 -5
- package/en/apis/app/runtime/web-server/middleware.mdx +6 -6
- package/en/components/global-proxy-config.mdx +3 -3
- package/en/components/init-app.mdx +5 -5
- package/en/configure/app/bff/_category_.json +4 -0
- package/en/configure/app/bff/prefix.mdx +2 -3
- package/en/configure/app/bff/proxy.mdx +1 -1
- package/en/configure/app/builder-plugins.mdx +3 -3
- package/en/configure/app/deploy/_category_.json +4 -0
- package/en/configure/app/dev/_category_.json +4 -0
- package/en/configure/app/dev/asset-prefix.mdx +1 -1
- package/en/configure/app/dev/before-start-url.mdx +13 -0
- package/en/configure/app/dev/hmr.mdx +1 -1
- package/en/configure/app/dev/host.mdx +13 -0
- package/en/configure/app/dev/https.mdx +1 -1
- package/en/configure/app/dev/port.mdx +1 -1
- package/en/configure/app/dev/progress-bar.mdx +1 -1
- package/en/configure/app/dev/start-url.mdx +1 -1
- package/en/configure/app/experiments/_category_.json +4 -0
- package/en/configure/app/experiments/lazy-compilation.mdx +1 -1
- package/en/configure/app/html/_category_.json +4 -0
- package/en/configure/app/html/app-icon.mdx +1 -1
- package/en/configure/app/html/crossorigin.mdx +1 -1
- package/en/configure/app/html/disable-html-folder.mdx +1 -1
- package/en/configure/app/html/favicon-by-entries.mdx +1 -1
- package/en/configure/app/html/favicon.mdx +1 -1
- package/en/configure/app/html/inject-by-entries.mdx +1 -1
- package/en/configure/app/html/inject.mdx +1 -1
- package/en/configure/app/html/meta-by-entries.mdx +1 -1
- package/en/configure/app/html/meta.mdx +1 -1
- package/en/configure/app/html/mount-id.mdx +1 -1
- package/en/configure/app/html/tags-by-entries.mdx +1 -1
- package/en/configure/app/html/tags.mdx +1 -1
- package/en/configure/app/html/template-by-entries.mdx +1 -1
- package/en/configure/app/html/template-parameters-by-entries.mdx +1 -1
- package/en/configure/app/html/template-parameters.mdx +1 -1
- package/en/configure/app/html/template.mdx +1 -1
- package/en/configure/app/html/title-by-entries.mdx +1 -1
- package/en/configure/app/html/title.mdx +1 -1
- package/en/configure/app/output/_category_.json +4 -0
- package/en/configure/app/output/asset-prefix.mdx +1 -1
- package/en/configure/app/output/assets-retry.mdx +1 -1
- package/en/configure/app/output/charset.mdx +1 -1
- package/en/configure/app/output/clean-dist-path.mdx +1 -1
- package/en/configure/app/output/convert-to-rem.mdx +1 -1
- package/en/configure/app/output/copy.mdx +1 -1
- package/en/configure/app/output/css-module-local-ident-name.mdx +1 -1
- package/en/configure/app/output/data-uri-limit.mdx +1 -1
- package/en/configure/app/output/disable-css-extract.mdx +1 -1
- package/en/configure/app/output/disable-css-module-extension.mdx +1 -1
- package/en/configure/app/output/disable-filename-hash.mdx +1 -1
- package/en/configure/app/output/disable-inline-runtime-chunk.mdx +1 -1
- package/en/configure/app/output/disable-minimize.mdx +1 -1
- package/en/configure/app/output/disable-source-map.mdx +1 -1
- package/en/configure/app/output/disable-ts-checker.mdx +1 -1
- package/en/configure/app/output/dist-path.mdx +1 -1
- package/en/configure/app/output/enable-asset-fallback.mdx +1 -1
- package/en/configure/app/output/enable-asset-manifest.mdx +1 -1
- package/en/configure/app/output/enable-css-module-tsdeclaration.mdx +1 -1
- package/en/configure/app/output/enable-inline-scripts.mdx +1 -1
- package/en/configure/app/output/enable-inline-styles.mdx +1 -1
- package/en/configure/app/output/enable-latest-decorators.mdx +1 -1
- package/en/configure/app/output/externals.mdx +1 -1
- package/en/configure/app/output/filename.mdx +1 -1
- package/en/configure/app/output/legal-comments.mdx +1 -1
- package/en/configure/app/output/override-browserslist.mdx +1 -1
- package/en/configure/app/output/polyfill.mdx +1 -1
- package/en/configure/app/output/ssg.mdx +5 -5
- package/en/configure/app/output/svg-default-export.mdx +1 -1
- package/en/configure/app/performance/_category_.json +4 -0
- package/en/configure/app/performance/build-cache.mdx +1 -1
- package/en/configure/app/performance/bundle-analyze.mdx +1 -1
- package/en/configure/app/performance/chunk-split.mdx +1 -1
- package/en/configure/app/performance/print-file-size.mdx +1 -1
- package/en/configure/app/performance/profile.mdx +1 -1
- package/en/configure/app/performance/remove-console.mdx +1 -1
- package/en/configure/app/performance/remove-moment-locale.mdx +1 -1
- package/en/configure/app/plugins.mdx +1 -1
- package/en/configure/app/runtime/_category_.json +4 -0
- package/en/configure/app/runtime/intro.mdx +2 -2
- package/en/configure/app/runtime/master-app.mdx +1 -1
- package/en/configure/app/security/_category_.json +4 -0
- package/en/configure/app/security/check-syntax.mdx +1 -1
- package/en/configure/app/security/sri.mdx +1 -1
- package/en/configure/app/server/_category_.json +4 -0
- package/en/configure/app/server/base-url.mdx +3 -3
- package/en/configure/app/server/enable-framework-ext.mdx +1 -1
- package/en/configure/app/server/ssr-by-entries.mdx +1 -1
- package/en/configure/app/source/_category_.json +4 -0
- package/en/configure/app/source/alias.mdx +1 -1
- package/en/configure/app/source/compile-js-data-uri.mdx +1 -1
- package/en/configure/app/source/define.mdx +1 -1
- package/en/configure/app/source/design-system.mdx +5 -5
- package/en/configure/app/source/entries-dir.mdx +1 -1
- package/en/configure/app/source/entries.mdx +3 -3
- package/en/configure/app/source/exclude.mdx +1 -1
- package/en/configure/app/source/global-vars.mdx +1 -1
- package/en/configure/app/source/include.mdx +1 -1
- package/en/configure/app/source/module-scopes.mdx +1 -1
- package/en/configure/app/source/pre-entry.mdx +1 -1
- package/en/configure/app/source/resolve-extension-prefix.mdx +1 -1
- package/en/configure/app/source/resolve-main-fields.mdx +1 -1
- package/en/configure/app/testing/_category_.json +4 -0
- package/en/configure/app/testing/transformer.mdx +1 -1
- package/en/configure/app/tools/_category_.json +4 -0
- package/en/configure/app/tools/autoprefixer.mdx +1 -1
- package/en/configure/app/tools/babel.mdx +1 -1
- package/en/configure/app/tools/css-extract.mdx +1 -1
- package/en/configure/app/tools/css-loader.mdx +1 -1
- package/en/configure/app/tools/dev-server.mdx +1 -1
- package/en/configure/app/tools/html-plugin.mdx +1 -1
- package/en/configure/app/tools/inspector.mdx +1 -1
- package/en/configure/app/tools/jest.mdx +1 -1
- package/en/configure/app/tools/less.mdx +1 -1
- package/en/configure/app/tools/minify-css.mdx +1 -1
- package/en/configure/app/tools/postcss.mdx +1 -1
- package/en/configure/app/tools/pug.mdx +1 -1
- package/en/configure/app/tools/rspack.mdx +13 -0
- package/en/configure/app/tools/sass.mdx +1 -1
- package/en/configure/app/tools/style-loader.mdx +1 -1
- package/en/configure/app/tools/styled-components.mdx +1 -1
- package/en/configure/app/tools/tailwindcss.mdx +1 -1
- package/en/configure/app/tools/terser.mdx +1 -1
- package/en/configure/app/tools/ts-checker.mdx +1 -1
- package/en/configure/app/tools/ts-loader.mdx +1 -1
- package/en/configure/app/tools/webpack-chain.mdx +1 -1
- package/en/configure/app/tools/webpack.mdx +1 -1
- package/en/configure/app/usage.mdx +1 -1
- package/en/guides/advanced-features/_category_.json +2 -2
- package/en/guides/advanced-features/bff/bff-proxy.mdx +1 -1
- package/en/guides/advanced-features/bff/frameworks.mdx +1 -1
- package/en/guides/advanced-features/bff/function.mdx +3 -3
- package/en/guides/advanced-features/code-split.mdx +2 -2
- package/en/guides/advanced-features/compatibility.mdx +2 -3
- package/en/guides/advanced-features/eslint.mdx +4 -4
- package/en/guides/advanced-features/low-level.mdx +1 -1
- package/en/guides/advanced-features/rspack-start.mdx +69 -0
- package/en/guides/advanced-features/ssg.mdx +12 -13
- package/en/guides/advanced-features/ssr.mdx +3 -3
- package/en/guides/advanced-features/testing.mdx +4 -5
- package/en/guides/advanced-features/web-server.mdx +0 -1
- package/en/guides/basic-features/alias.mdx +5 -5
- package/en/guides/basic-features/data-fetch.mdx +25 -12
- package/en/guides/basic-features/env-vars.mdx +1 -1
- package/en/guides/basic-features/html.mdx +11 -11
- package/en/guides/basic-features/mock.mdx +21 -1
- package/en/guides/basic-features/proxy.mdx +2 -2
- package/en/guides/basic-features/routes.mdx +29 -15
- package/en/guides/{basic-features → concept}/builder.mdx +2 -2
- package/en/guides/concept/entries.mdx +11 -11
- package/en/guides/css/_category_.json +5 -0
- package/en/guides/{basic-features/css → css}/less-sass.mdx +1 -1
- package/en/guides/get-started/introduction.mdx +34 -0
- package/en/guides/get-started/quick-start.mdx +4 -4
- package/en/guides/get-started/upgrade.mdx +2 -1
- package/en/guides/topic-detail/_category_.json +2 -2
- package/en/guides/topic-detail/framework-plugin/hook.mdx +1 -1
- package/en/guides/topic-detail/generator/plugin/api/hook/onForged.mdx +1 -1
- package/en/guides/topic-detail/generator/plugin/develop.mdx +1 -1
- package/en/guides/topic-detail/micro-frontend/c02-development.mdx +128 -61
- package/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +73 -42
- package/en/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +1 -1
- package/en/guides/topic-detail/model/auto-actions.mdx +1 -1
- package/en/guides/topic-detail/model/define-model.mdx +1 -1
- package/en/guides/topic-detail/model/manage-effects.mdx +1 -1
- package/en/guides/topic-detail/model/model-communicate.mdx +1 -1
- package/en/guides/topic-detail/model/quick-start.mdx +2 -2
- package/en/guides/topic-detail/model/test-model.mdx +1 -1
- package/en/guides/topic-detail/model/use-model.mdx +3 -3
- package/en/guides/troubleshooting/_category_.json +2 -2
- package/en/guides/troubleshooting/cli.mdx +1 -1
- package/en/index.md +1 -1
- package/en/tutorials/first-app/_category_.json +1 -1
- package/en/tutorials/first-app/c01-start.mdx +0 -1
- package/en/tutorials/first-app/c03-css.mdx +1 -2
- package/en/tutorials/first-app/c06-model.mdx +1 -1
- package/en/tutorials/first-app/c07-container.mdx +18 -18
- package/en/tutorials/first-app/c08-entries.mdx +24 -25
- package/en/tutorials/foundations/introduction.mdx +17 -34
- package/package.json +3 -3
- package/scripts/config.ts +3 -1
- package/scripts/summary.en.json +1 -1
- package/scripts/summary.zh.json +1 -1
- package/zh/apis/app/commands.mdx +299 -0
- package/zh/apis/app/hooks/_category_.json +2 -5
- package/zh/apis/app/hooks/src/pages.mdx +1 -1
- package/zh/apis/app/hooks/src/routes.mdx +3 -3
- package/zh/apis/app/runtime/_category_.json +1 -5
- package/zh/apis/app/runtime/core/create-app.mdx +1 -1
- package/zh/apis/app/runtime/core/use-module-apps.mdx +81 -40
- package/zh/apis/app/runtime/model/Provider.mdx +2 -2
- package/zh/apis/app/runtime/model/create-app.mdx +7 -7
- package/zh/apis/app/runtime/model/create-store.mdx +2 -2
- package/zh/apis/app/runtime/model/use-local-model.mdx +1 -1
- package/zh/apis/app/runtime/model/use-static-model.mdx +1 -1
- package/zh/apis/app/runtime/model/use-store.mdx +1 -1
- package/zh/apis/app/runtime/testing/renderApp.mdx +1 -1
- package/zh/components/init-app.mdx +5 -5
- package/zh/components/micro-runtime-config.mdx +6 -6
- package/zh/components/release-note.mdx +1 -1
- package/zh/configure/app/bff/prefix.mdx +1 -1
- package/zh/configure/app/bff/proxy.mdx +1 -1
- package/zh/configure/app/builder-plugins.mdx +3 -3
- package/zh/configure/app/dev/before-start-url.mdx +13 -0
- package/zh/configure/app/dev/host.mdx +13 -0
- package/zh/configure/app/output/ssg.mdx +3 -3
- package/zh/configure/app/plugins.mdx +1 -1
- package/zh/configure/app/server/ssr-by-entries.mdx +1 -1
- package/zh/configure/app/source/entries-dir.mdx +1 -1
- package/zh/configure/app/tools/rspack.mdx +13 -0
- package/zh/configure/app/usage.mdx +1 -1
- package/zh/guides/advanced-features/_category_.json +2 -6
- package/zh/guides/advanced-features/compatibility.mdx +0 -1
- package/zh/guides/advanced-features/rspack-start.mdx +69 -0
- package/zh/guides/advanced-features/ssg.mdx +8 -9
- package/zh/guides/advanced-features/ssr.mdx +3 -2
- package/zh/guides/advanced-features/testing.mdx +0 -1
- package/zh/guides/advanced-features/web-server.mdx +0 -1
- package/zh/guides/basic-features/_category_.json +1 -5
- package/zh/guides/basic-features/alias.mdx +5 -5
- package/zh/guides/basic-features/data-fetch.mdx +39 -30
- package/zh/guides/basic-features/html.mdx +10 -9
- package/zh/guides/basic-features/mock.mdx +20 -0
- package/zh/guides/basic-features/routes.mdx +38 -17
- package/zh/guides/{basic-features → concept}/builder.mdx +4 -4
- package/zh/guides/concept/entries.mdx +11 -11
- package/zh/guides/css/_category_.json +5 -0
- package/zh/guides/{basic-features/css → css}/less-sass.mdx +1 -1
- package/zh/guides/{basic-features/css → css}/postcss.mdx +5 -4
- package/zh/guides/{basic-features/css → css}/tailwindcss.mdx +0 -1
- package/zh/guides/get-started/introduction.mdx +31 -0
- package/zh/guides/get-started/quick-start.mdx +4 -5
- package/zh/guides/get-started/upgrade.mdx +2 -1
- package/zh/guides/topic-detail/_category_.json +2 -2
- package/zh/guides/topic-detail/generator/plugin/api/input/addInputBefore.mdx +1 -1
- package/zh/guides/topic-detail/micro-frontend/c02-development.mdx +25 -0
- package/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +16 -16
- package/zh/guides/topic-detail/model/model-communicate.mdx +1 -1
- package/zh/guides/troubleshooting/_category_.json +2 -2
- package/zh/index.md +1 -1
- package/zh/tutorials/first-app/_category_.json +1 -1
- package/zh/tutorials/first-app/c01-start.mdx +1 -2
- package/zh/tutorials/first-app/c03-css.mdx +1 -2
- package/zh/tutorials/first-app/c06-model.mdx +2 -2
- package/zh/tutorials/first-app/c07-container.mdx +18 -18
- package/zh/tutorials/first-app/c08-entries.mdx +25 -26
- package/zh/tutorials/foundations/introduction.mdx +14 -29
- package/en/apis/app/commands/_category_.json +0 -8
- package/en/apis/app/commands/build.mdx +0 -39
- package/en/apis/app/commands/dev.mdx +0 -61
- package/en/apis/app/commands/index.mdx +0 -7
- package/en/apis/app/commands/inspect.mdx +0 -61
- package/en/apis/app/commands/lint.mdx +0 -19
- package/en/apis/app/commands/new.mdx +0 -54
- package/en/apis/app/commands/serve.mdx +0 -27
- package/en/apis/app/commands/test.mdx +0 -35
- package/en/apis/app/commands/upgrade.mdx +0 -18
- package/en/apis/app/hooks/index.mdx +0 -7
- package/en/apis/app/runtime/index.mdx +0 -7
- package/en/guides/advanced-features/index.mdx +0 -7
- package/en/guides/basic-features/css/_category_.json +0 -4
- package/zh/apis/app/commands/_category_.json +0 -8
- package/zh/apis/app/commands/build.mdx +0 -39
- package/zh/apis/app/commands/dev.mdx +0 -61
- package/zh/apis/app/commands/index.mdx +0 -7
- package/zh/apis/app/commands/inspect.mdx +0 -61
- package/zh/apis/app/commands/lint.mdx +0 -19
- package/zh/apis/app/commands/new.mdx +0 -54
- package/zh/apis/app/commands/serve.mdx +0 -27
- package/zh/apis/app/commands/test.mdx +0 -35
- package/zh/apis/app/commands/upgrade.mdx +0 -18
- package/zh/apis/app/hooks/index.mdx +0 -7
- package/zh/apis/app/runtime/index.mdx +0 -7
- package/zh/guides/advanced-features/index.mdx +0 -7
- package/zh/guides/basic-features/css/_category_.json +0 -4
- package/zh/guides/basic-features/index.mdx +0 -7
- /package/en/guides/{basic-features/css → css}/css-in-js.mdx +0 -0
- /package/en/guides/{basic-features/css → css}/css-modules.mdx +0 -0
- /package/en/guides/{basic-features/css → css}/postcss.mdx +0 -0
- /package/en/guides/{basic-features/css → css}/tailwindcss.mdx +0 -0
- /package/zh/guides/{basic-features/css → css}/css-in-js.mdx +0 -0
- /package/zh/guides/{basic-features/css → css}/css-modules.mdx +0 -0
@@ -255,28 +255,28 @@ The refactoring is complete, and the current project structure is:
|
|
255
255
|
├── package.json
|
256
256
|
├── pnpm-lock.yaml
|
257
257
|
├── src
|
258
|
-
│
|
259
|
-
│
|
260
|
-
│
|
261
|
-
│
|
262
|
-
│
|
263
|
-
│
|
264
|
-
│
|
265
|
-
│
|
266
|
-
│
|
267
|
-
│
|
268
|
-
│
|
269
|
-
│
|
270
|
-
│
|
271
|
-
│
|
272
|
-
│
|
273
|
-
│
|
274
|
-
│
|
258
|
+
│ ├── components
|
259
|
+
│ │ ├── Avatar
|
260
|
+
│ │ │ └── index.tsx
|
261
|
+
│ │ └── Item
|
262
|
+
│ │ └── index.tsx
|
263
|
+
│ ├── containers
|
264
|
+
│ │ └── Contacts.tsx
|
265
|
+
│ ├── models
|
266
|
+
│ │ └── contacts.ts
|
267
|
+
│ ├── modern-app-env.d.ts
|
268
|
+
│ ├── routes
|
269
|
+
│ │ ├── archives
|
270
|
+
│ │ │ └── page.tsx
|
271
|
+
│ │ ├── layout.tsx
|
272
|
+
│ │ └── page.tsx
|
273
|
+
│ └── styles
|
274
|
+
│ └── utils.css
|
275
275
|
└── tsconfig.json
|
276
276
|
```
|
277
277
|
|
278
278
|
The **view components** in `components/` dir are in the form of directories, such as `Avatar/index.tsx`. And the **container components** in `containers/` dir are in the form of single files, such as `contacts.tsx`. **This is a best practice we recommend**.
|
279
279
|
|
280
|
-
As mentioned in the chapter [Add UI component](./c02-component.
|
280
|
+
As mentioned in the chapter [Add UI component](./c02-component.mdx), the view component is in the form of a directory, because the view component is responsible for the implementation of UI display and interaction details, and can evolve in complexity. In the form of a directory, it is convenient to add sub-files, including dedicated resources (pictures, etc.), dedicated sub-components, CSS files, etc. You can reconstruct at will within this directory, considering only the smallest parts.
|
281
281
|
|
282
282
|
The container component is only responsible for linkage and is a glue layer. The sophisticated business logic and implementation details are handed over to the View layer and the Model layer for implementation. The container component itself should be kept simple and clear, and should not contain complex implementation details, so there should be no internal structure. The single-file form is not only more concise, but also acts as a constraint, reminding developers not to write complicated container components.
|
@@ -29,29 +29,29 @@ When created, the project will look like this:
|
|
29
29
|
├── package.json
|
30
30
|
├── pnpm-lock.yaml
|
31
31
|
├── src
|
32
|
-
│
|
33
|
-
│
|
34
|
-
│
|
35
|
-
│
|
36
|
-
│
|
37
|
-
│
|
38
|
-
│
|
39
|
-
│
|
40
|
-
│
|
41
|
-
│
|
42
|
-
│
|
43
|
-
│
|
44
|
-
│
|
45
|
-
│
|
46
|
-
│
|
47
|
-
│
|
48
|
-
│
|
49
|
-
│
|
50
|
-
│
|
51
|
-
│
|
52
|
-
│
|
53
|
-
│
|
54
|
-
│
|
32
|
+
│ ├── modern-app-env.d.ts
|
33
|
+
│ ├── landing-page
|
34
|
+
│ │ └── routes
|
35
|
+
│ │ ├── index.css
|
36
|
+
│ │ ├── layout.tsx
|
37
|
+
│ │ └── page.tsx
|
38
|
+
│ └── myapp
|
39
|
+
│ ├── components
|
40
|
+
│ │ ├── Avatar
|
41
|
+
│ │ │ └── index.tsx
|
42
|
+
│ │ └── Item
|
43
|
+
│ │ └── index.tsx
|
44
|
+
│ ├── containers
|
45
|
+
│ │ └── Contacts.tsx
|
46
|
+
│ ├── models
|
47
|
+
│ │ └── contacts.ts
|
48
|
+
│ ├── routes
|
49
|
+
│ │ ├── archives
|
50
|
+
│ │ │ └── page.tsx
|
51
|
+
│ │ ├── layout.tsx
|
52
|
+
│ │ └── page.tsx
|
53
|
+
│ └── styles
|
54
|
+
│ └── utils.css
|
55
55
|
└── tsconfig.json
|
56
56
|
```
|
57
57
|
|
@@ -93,11 +93,10 @@ In the Modern.js configuration file, we can write our own code to control the co
|
|
93
93
|
|
94
94
|
Now, modify the `modern.config.ts` to add something:
|
95
95
|
|
96
|
-
```ts
|
96
|
+
```ts title="modern.config.ts"
|
97
97
|
import appTools, { defineConfig } from '@modern-js/app-tools';
|
98
98
|
import tailwindcssPlugin from '@modern-js/plugin-tailwindcss';
|
99
99
|
|
100
|
-
// https://modernjs.dev/docs/apis/app/config
|
101
100
|
export default defineConfig({
|
102
101
|
runtime: {
|
103
102
|
router: true,
|
@@ -1,47 +1,30 @@
|
|
1
1
|
---
|
2
|
-
title:
|
2
|
+
title: Introduction
|
3
3
|
sidebar_position: 1
|
4
4
|
---
|
5
|
-
|
5
|
+
|
6
|
+
# Introduction
|
6
7
|
|
7
8
|
Welcome to Modern.js tutorials!
|
8
9
|
|
9
10
|
After reading this section, you will have an initial understanding of Modern.js and use Modern.js to create your first application.
|
10
11
|
|
11
|
-
|
12
|
-
Join our Lark group to ask questions and learn about the latest news.
|
13
|
-
|
14
|
-
:::
|
15
|
-
|
16
|
-
## What is Modern.js
|
17
|
-
|
18
|
-
**Modern.js** is a progressive modern web development framework based on React.
|
19
|
-
|
20
|
-
The framework has a variety of built-in out-of-the-box tools, excellent build performance, zero-configuration rendering paradigm switching, and integrated API calls. Starting from three solutions (Application solutions, Module solutions, Monorepo solutions), it supports front-end research and development of a complete period.
|
21
|
-
|
22
|
-
Modern.js is ByteDance's underlying front-end framework, which has directly or indirectly served thousands of applications, including middle and back-end, PC Web, H5 and other application scenarios. The framework covers a full life cycle, has a complete plugin system, and provides a high degree of customization capabilities. Support custom solutions exclusive to business lines through generator plugin, customize various functional extensions and business requirements, and help developers build applications faster.
|
23
|
-
|
24
|
-
## Why Modern.js
|
25
|
-
|
26
|
-
Modern.js can provide developers with the ultimate **Development Experience**,make the app better **User Experience**。
|
27
|
-
|
28
|
-
In the process of developing React applications, developers often need to design implementations for certain functions, or use other libraries and frameworks to solve these problems。
|
29
|
-
|
30
|
-
Modern.js support all the configuration and tools required by React applications, and have built-in **additional functions and optimizations**. Developers can use React to build the UI of the application, and then gradually adopt Modern.js functions to solve common application requirements, such as routing, data fetch, state management, etc.
|
31
|
-
|
32
|
-
It mainly contains the following features:
|
12
|
+
## What is Modern.js?
|
33
13
|
|
34
|
-
|
35
|
-
- 🏠 **Integration**:The development is unique to the production environment Web Server, CSR and SSR are isomorphic development, and the function as the API service call.
|
36
|
-
- 📦 **Out Of The Box**:Default TS support, built-in build core, ESLint, debugging tools, full functionality can be tested.
|
37
|
-
- 🌏 **Ecology**:Self-developed state management, micro frontend, module packaging, Monorepo solution and other peripheral requirements.
|
38
|
-
- 🕸 **Routing Modes**:Contains controlled routing, routing based on file conventions (nested routing), configurable routing, etc。
|
39
|
-
- 🚀 **Independently Build Core**:Support a variety of packaging tools, deep optimization bundle.
|
14
|
+
If you don't know Modern.js yet, please can read [Modern.js Introduction](/guides/get-started/introduction) first.
|
40
15
|
|
41
|
-
##
|
16
|
+
## Tutorial
|
42
17
|
|
43
|
-
|
18
|
+
We have prepared a tutorial on creating a "contact list app" that you can follow step by step to create an app and learn about the following practices in Modern.js:
|
44
19
|
|
45
|
-
|
20
|
+
- Creating a project
|
21
|
+
- Using the antd component library
|
22
|
+
- Integrating Tailwind CSS
|
23
|
+
- Client-side routing
|
24
|
+
- Data fetching
|
25
|
+
- State Management
|
26
|
+
- Container components
|
27
|
+
- New portal
|
28
|
+
- ...
|
46
29
|
|
47
|
-
|
30
|
+
Translated with www.DeepL.com/Translator (free version)
|
package/package.json
CHANGED
@@ -11,13 +11,13 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "2.
|
14
|
+
"version": "2.6.0",
|
15
15
|
"publishConfig": {
|
16
16
|
"registry": "https://registry.npmjs.org/",
|
17
17
|
"access": "public"
|
18
18
|
},
|
19
19
|
"peerDependencies": {
|
20
|
-
"@modern-js/builder-doc": "^2.
|
20
|
+
"@modern-js/builder-doc": "^2.6.0"
|
21
21
|
},
|
22
22
|
"devDependencies": {
|
23
23
|
"ts-node": "^10",
|
@@ -25,7 +25,7 @@
|
|
25
25
|
"fs-extra": "^10",
|
26
26
|
"@types/node": "^16",
|
27
27
|
"@types/fs-extra": "^9",
|
28
|
-
"@modern-js/builder-doc": "2.
|
28
|
+
"@modern-js/builder-doc": "2.6.0"
|
29
29
|
},
|
30
30
|
"scripts": {
|
31
31
|
"build": "npx ts-node ./scripts/sync.ts"
|
package/scripts/config.ts
CHANGED
@@ -27,7 +27,9 @@ sidebar_label: ${name}
|
|
27
27
|
:::tip
|
28
28
|
${
|
29
29
|
tip[lng]
|
30
|
-
} [${dirname}.${name}](https://modernjs.dev/builder${langPrefix}/api/config-${dirname}.html#${dirname}${name.toLowerCase()})
|
30
|
+
} [${dirname}.${name}](https://modernjs.dev/builder${langPrefix}/api/config-${dirname}.html#${dirname}${name.toLowerCase()})${
|
31
|
+
lng === 'en' ? '.' : '。'
|
32
|
+
}
|
31
33
|
:::
|
32
34
|
|
33
35
|
import Main from '@modern-js/builder-doc/docs/${lng}/config/${dirname}/${name}.md'
|
package/scripts/summary.en.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
[{"name":"assetPrefix","dirname":"dev"},{"name":"hmr","dirname":"dev"},{"name":"https","dirname":"dev"},{"name":"port","dirname":"dev"},{"name":"progressBar","dirname":"dev"},{"name":"startUrl","dirname":"dev"},{"name":"lazyCompilation","dirname":"experiments"},{"name":"appIcon","dirname":"html"},{"name":"crossorigin","dirname":"html"},{"name":"disableHtmlFolder","dirname":"html"},{"name":"favicon","dirname":"html"},{"name":"faviconByEntries","dirname":"html"},{"name":"inject","dirname":"html"},{"name":"injectByEntries","dirname":"html"},{"name":"meta","dirname":"html"},{"name":"metaByEntries","dirname":"html"},{"name":"mountId","dirname":"html"},{"name":"tags","dirname":"html"},{"name":"tagsByEntries","dirname":"html"},{"name":"template","dirname":"html"},{"name":"templateByEntries","dirname":"html"},{"name":"templateParameters","dirname":"html"},{"name":"templateParametersByEntries","dirname":"html"},{"name":"title","dirname":"html"},{"name":"titleByEntries","dirname":"html"},{"name":"assetPrefix","dirname":"output"},{"name":"assetsRetry","dirname":"output"},{"name":"charset","dirname":"output"},{"name":"cleanDistPath","dirname":"output"},{"name":"convertToRem","dirname":"output"},{"name":"copy","dirname":"output"},{"name":"cssModuleLocalIdentName","dirname":"output"},{"name":"dataUriLimit","dirname":"output"},{"name":"disableCssExtract","dirname":"output"},{"name":"disableCssModuleExtension","dirname":"output"},{"name":"disableFilenameHash","dirname":"output"},{"name":"disableInlineRuntimeChunk","dirname":"output"},{"name":"disableMinimize","dirname":"output"},{"name":"disableSourceMap","dirname":"output"},{"name":"disableTsChecker","dirname":"output"},{"name":"distPath","dirname":"output"},{"name":"enableAssetFallback","dirname":"output"},{"name":"enableAssetManifest","dirname":"output"},{"name":"enableCssModuleTSDeclaration","dirname":"output"},{"name":"enableInlineScripts","dirname":"output"},{"name":"enableInlineStyles","dirname":"output"},{"name":"enableLatestDecorators","dirname":"output"},{"name":"externals","dirname":"output"},{"name":"filename","dirname":"output"},{"name":"legalComments","dirname":"output"},{"name":"overrideBrowserslist","dirname":"output"},{"name":"polyfill","dirname":"output"},{"name":"svgDefaultExport","dirname":"output"},{"name":"buildCache","dirname":"performance"},{"name":"bundleAnalyze","dirname":"performance"},{"name":"chunkSplit","dirname":"performance"},{"name":"printFileSize","dirname":"performance"},{"name":"profile","dirname":"performance"},{"name":"removeConsole","dirname":"performance"},{"name":"removeMomentLocale","dirname":"performance"},{"name":"checkSyntax","dirname":"security"},{"name":"sri","dirname":"security"},{"name":"alias","dirname":"source"},{"name":"compileJsDataURI","dirname":"source"},{"name":"define","dirname":"source"},{"name":"exclude","dirname":"source"},{"name":"globalVars","dirname":"source"},{"name":"include","dirname":"source"},{"name":"moduleScopes","dirname":"source"},{"name":"preEntry","dirname":"source"},{"name":"resolveExtensionPrefix","dirname":"source"},{"name":"resolveMainFields","dirname":"source"},{"name":"autoprefixer","dirname":"tools"},{"name":"babel","dirname":"tools"},{"name":"cssExtract","dirname":"tools"},{"name":"cssLoader","dirname":"tools"},{"name":"devServer","dirname":"tools"},{"name":"htmlPlugin","dirname":"tools"},{"name":"inspector","dirname":"tools"},{"name":"less","dirname":"tools"},{"name":"minifyCss","dirname":"tools"},{"name":"postcss","dirname":"tools"},{"name":"pug","dirname":"tools"},{"name":"sass","dirname":"tools"},{"name":"styleLoader","dirname":"tools"},{"name":"styledComponents","dirname":"tools"},{"name":"terser","dirname":"tools"},{"name":"tsChecker","dirname":"tools"},{"name":"tsLoader","dirname":"tools"},{"name":"webpack","dirname":"tools"},{"name":"webpackChain","dirname":"tools"}]
|
1
|
+
[{"name":"assetPrefix","dirname":"dev"},{"name":"beforeStartUrl","dirname":"dev"},{"name":"hmr","dirname":"dev"},{"name":"host","dirname":"dev"},{"name":"https","dirname":"dev"},{"name":"port","dirname":"dev"},{"name":"progressBar","dirname":"dev"},{"name":"startUrl","dirname":"dev"},{"name":"lazyCompilation","dirname":"experiments"},{"name":"appIcon","dirname":"html"},{"name":"crossorigin","dirname":"html"},{"name":"disableHtmlFolder","dirname":"html"},{"name":"favicon","dirname":"html"},{"name":"faviconByEntries","dirname":"html"},{"name":"inject","dirname":"html"},{"name":"injectByEntries","dirname":"html"},{"name":"meta","dirname":"html"},{"name":"metaByEntries","dirname":"html"},{"name":"mountId","dirname":"html"},{"name":"tags","dirname":"html"},{"name":"tagsByEntries","dirname":"html"},{"name":"template","dirname":"html"},{"name":"templateByEntries","dirname":"html"},{"name":"templateParameters","dirname":"html"},{"name":"templateParametersByEntries","dirname":"html"},{"name":"title","dirname":"html"},{"name":"titleByEntries","dirname":"html"},{"name":"assetPrefix","dirname":"output"},{"name":"assetsRetry","dirname":"output"},{"name":"charset","dirname":"output"},{"name":"cleanDistPath","dirname":"output"},{"name":"convertToRem","dirname":"output"},{"name":"copy","dirname":"output"},{"name":"cssModuleLocalIdentName","dirname":"output"},{"name":"dataUriLimit","dirname":"output"},{"name":"disableCssExtract","dirname":"output"},{"name":"disableCssModuleExtension","dirname":"output"},{"name":"disableFilenameHash","dirname":"output"},{"name":"disableInlineRuntimeChunk","dirname":"output"},{"name":"disableMinimize","dirname":"output"},{"name":"disableSourceMap","dirname":"output"},{"name":"disableTsChecker","dirname":"output"},{"name":"distPath","dirname":"output"},{"name":"enableAssetFallback","dirname":"output"},{"name":"enableAssetManifest","dirname":"output"},{"name":"enableCssModuleTSDeclaration","dirname":"output"},{"name":"enableInlineScripts","dirname":"output"},{"name":"enableInlineStyles","dirname":"output"},{"name":"enableLatestDecorators","dirname":"output"},{"name":"externals","dirname":"output"},{"name":"filename","dirname":"output"},{"name":"legalComments","dirname":"output"},{"name":"overrideBrowserslist","dirname":"output"},{"name":"polyfill","dirname":"output"},{"name":"svgDefaultExport","dirname":"output"},{"name":"buildCache","dirname":"performance"},{"name":"bundleAnalyze","dirname":"performance"},{"name":"chunkSplit","dirname":"performance"},{"name":"printFileSize","dirname":"performance"},{"name":"profile","dirname":"performance"},{"name":"removeConsole","dirname":"performance"},{"name":"removeMomentLocale","dirname":"performance"},{"name":"checkSyntax","dirname":"security"},{"name":"sri","dirname":"security"},{"name":"alias","dirname":"source"},{"name":"compileJsDataURI","dirname":"source"},{"name":"define","dirname":"source"},{"name":"exclude","dirname":"source"},{"name":"globalVars","dirname":"source"},{"name":"include","dirname":"source"},{"name":"moduleScopes","dirname":"source"},{"name":"preEntry","dirname":"source"},{"name":"resolveExtensionPrefix","dirname":"source"},{"name":"resolveMainFields","dirname":"source"},{"name":"autoprefixer","dirname":"tools"},{"name":"babel","dirname":"tools"},{"name":"cssExtract","dirname":"tools"},{"name":"cssLoader","dirname":"tools"},{"name":"devServer","dirname":"tools"},{"name":"htmlPlugin","dirname":"tools"},{"name":"inspector","dirname":"tools"},{"name":"less","dirname":"tools"},{"name":"minifyCss","dirname":"tools"},{"name":"postcss","dirname":"tools"},{"name":"pug","dirname":"tools"},{"name":"rspack","dirname":"tools"},{"name":"sass","dirname":"tools"},{"name":"styleLoader","dirname":"tools"},{"name":"styledComponents","dirname":"tools"},{"name":"terser","dirname":"tools"},{"name":"tsChecker","dirname":"tools"},{"name":"tsLoader","dirname":"tools"},{"name":"webpack","dirname":"tools"},{"name":"webpackChain","dirname":"tools"}]
|
package/scripts/summary.zh.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
[{"name":"assetPrefix","dirname":"dev"},{"name":"hmr","dirname":"dev"},{"name":"https","dirname":"dev"},{"name":"port","dirname":"dev"},{"name":"progressBar","dirname":"dev"},{"name":"startUrl","dirname":"dev"},{"name":"lazyCompilation","dirname":"experiments"},{"name":"appIcon","dirname":"html"},{"name":"crossorigin","dirname":"html"},{"name":"disableHtmlFolder","dirname":"html"},{"name":"favicon","dirname":"html"},{"name":"faviconByEntries","dirname":"html"},{"name":"inject","dirname":"html"},{"name":"injectByEntries","dirname":"html"},{"name":"meta","dirname":"html"},{"name":"metaByEntries","dirname":"html"},{"name":"mountId","dirname":"html"},{"name":"tags","dirname":"html"},{"name":"tagsByEntries","dirname":"html"},{"name":"template","dirname":"html"},{"name":"templateByEntries","dirname":"html"},{"name":"templateParameters","dirname":"html"},{"name":"templateParametersByEntries","dirname":"html"},{"name":"title","dirname":"html"},{"name":"titleByEntries","dirname":"html"},{"name":"assetPrefix","dirname":"output"},{"name":"assetsRetry","dirname":"output"},{"name":"charset","dirname":"output"},{"name":"cleanDistPath","dirname":"output"},{"name":"convertToRem","dirname":"output"},{"name":"copy","dirname":"output"},{"name":"cssModuleLocalIdentName","dirname":"output"},{"name":"dataUriLimit","dirname":"output"},{"name":"disableCssExtract","dirname":"output"},{"name":"disableCssModuleExtension","dirname":"output"},{"name":"disableFilenameHash","dirname":"output"},{"name":"disableInlineRuntimeChunk","dirname":"output"},{"name":"disableMinimize","dirname":"output"},{"name":"disableSourceMap","dirname":"output"},{"name":"disableTsChecker","dirname":"output"},{"name":"distPath","dirname":"output"},{"name":"enableAssetFallback","dirname":"output"},{"name":"enableAssetManifest","dirname":"output"},{"name":"enableCssModuleTSDeclaration","dirname":"output"},{"name":"enableInlineScripts","dirname":"output"},{"name":"enableInlineStyles","dirname":"output"},{"name":"enableLatestDecorators","dirname":"output"},{"name":"externals","dirname":"output"},{"name":"filename","dirname":"output"},{"name":"legalComments","dirname":"output"},{"name":"overrideBrowserslist","dirname":"output"},{"name":"polyfill","dirname":"output"},{"name":"svgDefaultExport","dirname":"output"},{"name":"buildCache","dirname":"performance"},{"name":"bundleAnalyze","dirname":"performance"},{"name":"chunkSplit","dirname":"performance"},{"name":"printFileSize","dirname":"performance"},{"name":"profile","dirname":"performance"},{"name":"removeConsole","dirname":"performance"},{"name":"removeMomentLocale","dirname":"performance"},{"name":"checkSyntax","dirname":"security"},{"name":"sri","dirname":"security"},{"name":"alias","dirname":"source"},{"name":"compileJsDataURI","dirname":"source"},{"name":"define","dirname":"source"},{"name":"exclude","dirname":"source"},{"name":"globalVars","dirname":"source"},{"name":"include","dirname":"source"},{"name":"moduleScopes","dirname":"source"},{"name":"preEntry","dirname":"source"},{"name":"resolveExtensionPrefix","dirname":"source"},{"name":"resolveMainFields","dirname":"source"},{"name":"autoprefixer","dirname":"tools"},{"name":"babel","dirname":"tools"},{"name":"cssExtract","dirname":"tools"},{"name":"cssLoader","dirname":"tools"},{"name":"devServer","dirname":"tools"},{"name":"htmlPlugin","dirname":"tools"},{"name":"inspector","dirname":"tools"},{"name":"less","dirname":"tools"},{"name":"minifyCss","dirname":"tools"},{"name":"postcss","dirname":"tools"},{"name":"pug","dirname":"tools"},{"name":"sass","dirname":"tools"},{"name":"styleLoader","dirname":"tools"},{"name":"styledComponents","dirname":"tools"},{"name":"terser","dirname":"tools"},{"name":"tsChecker","dirname":"tools"},{"name":"tsLoader","dirname":"tools"},{"name":"webpack","dirname":"tools"},{"name":"webpackChain","dirname":"tools"}]
|
1
|
+
[{"name":"assetPrefix","dirname":"dev"},{"name":"beforeStartUrl","dirname":"dev"},{"name":"hmr","dirname":"dev"},{"name":"host","dirname":"dev"},{"name":"https","dirname":"dev"},{"name":"port","dirname":"dev"},{"name":"progressBar","dirname":"dev"},{"name":"startUrl","dirname":"dev"},{"name":"lazyCompilation","dirname":"experiments"},{"name":"appIcon","dirname":"html"},{"name":"crossorigin","dirname":"html"},{"name":"disableHtmlFolder","dirname":"html"},{"name":"favicon","dirname":"html"},{"name":"faviconByEntries","dirname":"html"},{"name":"inject","dirname":"html"},{"name":"injectByEntries","dirname":"html"},{"name":"meta","dirname":"html"},{"name":"metaByEntries","dirname":"html"},{"name":"mountId","dirname":"html"},{"name":"tags","dirname":"html"},{"name":"tagsByEntries","dirname":"html"},{"name":"template","dirname":"html"},{"name":"templateByEntries","dirname":"html"},{"name":"templateParameters","dirname":"html"},{"name":"templateParametersByEntries","dirname":"html"},{"name":"title","dirname":"html"},{"name":"titleByEntries","dirname":"html"},{"name":"assetPrefix","dirname":"output"},{"name":"assetsRetry","dirname":"output"},{"name":"charset","dirname":"output"},{"name":"cleanDistPath","dirname":"output"},{"name":"convertToRem","dirname":"output"},{"name":"copy","dirname":"output"},{"name":"cssModuleLocalIdentName","dirname":"output"},{"name":"dataUriLimit","dirname":"output"},{"name":"disableCssExtract","dirname":"output"},{"name":"disableCssModuleExtension","dirname":"output"},{"name":"disableFilenameHash","dirname":"output"},{"name":"disableInlineRuntimeChunk","dirname":"output"},{"name":"disableMinimize","dirname":"output"},{"name":"disableSourceMap","dirname":"output"},{"name":"disableTsChecker","dirname":"output"},{"name":"distPath","dirname":"output"},{"name":"enableAssetFallback","dirname":"output"},{"name":"enableAssetManifest","dirname":"output"},{"name":"enableCssModuleTSDeclaration","dirname":"output"},{"name":"enableInlineScripts","dirname":"output"},{"name":"enableInlineStyles","dirname":"output"},{"name":"enableLatestDecorators","dirname":"output"},{"name":"externals","dirname":"output"},{"name":"filename","dirname":"output"},{"name":"legalComments","dirname":"output"},{"name":"overrideBrowserslist","dirname":"output"},{"name":"polyfill","dirname":"output"},{"name":"svgDefaultExport","dirname":"output"},{"name":"buildCache","dirname":"performance"},{"name":"bundleAnalyze","dirname":"performance"},{"name":"chunkSplit","dirname":"performance"},{"name":"printFileSize","dirname":"performance"},{"name":"profile","dirname":"performance"},{"name":"removeConsole","dirname":"performance"},{"name":"removeMomentLocale","dirname":"performance"},{"name":"checkSyntax","dirname":"security"},{"name":"sri","dirname":"security"},{"name":"alias","dirname":"source"},{"name":"compileJsDataURI","dirname":"source"},{"name":"define","dirname":"source"},{"name":"exclude","dirname":"source"},{"name":"globalVars","dirname":"source"},{"name":"include","dirname":"source"},{"name":"moduleScopes","dirname":"source"},{"name":"preEntry","dirname":"source"},{"name":"resolveExtensionPrefix","dirname":"source"},{"name":"resolveMainFields","dirname":"source"},{"name":"autoprefixer","dirname":"tools"},{"name":"babel","dirname":"tools"},{"name":"cssExtract","dirname":"tools"},{"name":"cssLoader","dirname":"tools"},{"name":"devServer","dirname":"tools"},{"name":"htmlPlugin","dirname":"tools"},{"name":"inspector","dirname":"tools"},{"name":"less","dirname":"tools"},{"name":"minifyCss","dirname":"tools"},{"name":"postcss","dirname":"tools"},{"name":"pug","dirname":"tools"},{"name":"rspack","dirname":"tools"},{"name":"sass","dirname":"tools"},{"name":"styleLoader","dirname":"tools"},{"name":"styledComponents","dirname":"tools"},{"name":"terser","dirname":"tools"},{"name":"tsChecker","dirname":"tools"},{"name":"tsLoader","dirname":"tools"},{"name":"webpack","dirname":"tools"},{"name":"webpackChain","dirname":"tools"}]
|
@@ -0,0 +1,299 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 1
|
3
|
+
---
|
4
|
+
|
5
|
+
# 命令
|
6
|
+
|
7
|
+
Modern.js 内置了一些命令,可以帮助你快速启动开发服务器、构建生产环境代码等。
|
8
|
+
|
9
|
+
通过本章节,你可以了解到 Modern.js 内置的命令有哪些,以及如何使用这些命令。
|
10
|
+
|
11
|
+
## modern dev
|
12
|
+
|
13
|
+
`modern dev` 命令用于启动一个本地开发服务器,对源代码进行开发环境编译。
|
14
|
+
|
15
|
+
```bash
|
16
|
+
Usage: modern dev [options]
|
17
|
+
|
18
|
+
Options:
|
19
|
+
-e --entry <entry> 指定入口,只编译特定的页面
|
20
|
+
-c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
|
21
|
+
-h, --help 显示命令帮助
|
22
|
+
--analyze 分析构建产物体积,查看各个模块打包后的大小
|
23
|
+
--api-only 仅启动 API 接口服务
|
24
|
+
```
|
25
|
+
|
26
|
+
运行 `modern dev` 后,Modern.js 会监听源文件变化并进行模块热更新。
|
27
|
+
|
28
|
+
```bash
|
29
|
+
$ modern dev
|
30
|
+
|
31
|
+
info Starting dev server...
|
32
|
+
info App running at:
|
33
|
+
|
34
|
+
> Local: http://localhost:8080/
|
35
|
+
> Network: http://192.168.0.1:8080/
|
36
|
+
```
|
37
|
+
|
38
|
+
### 编译部分页面
|
39
|
+
|
40
|
+
在多页面(MPA)项目中,可以添加 `--entry` 参数来指定编译其中的一个或多个页面。这样可以只编译项目中的部分代码,从而提升 dev 启动速度。
|
41
|
+
|
42
|
+
比如执行 `modern dev --entry`,在命令行界面中会展示入口选择框:
|
43
|
+
|
44
|
+
```bash
|
45
|
+
$ modern dev --entry
|
46
|
+
|
47
|
+
? 请选择需要构建的入口
|
48
|
+
❯ ◯ foo
|
49
|
+
◯ bar
|
50
|
+
◯ baz
|
51
|
+
```
|
52
|
+
|
53
|
+
比如选择 `foo` 入口,那么只有 `foo` 入口相关的代码会进行编译,其他页面的代码将不会参与构建。
|
54
|
+
|
55
|
+
### 通过参数指定页面
|
56
|
+
|
57
|
+
你也可以在 `--entry` 后面通过参数来指定页面名称,多个页面的名称使用逗号分隔。
|
58
|
+
|
59
|
+
```bash
|
60
|
+
# 编译 foo 页面
|
61
|
+
modern dev --entry foo
|
62
|
+
|
63
|
+
# 编译 foo 和 bar 页面
|
64
|
+
modern dev --entry foo,bar
|
65
|
+
```
|
66
|
+
|
67
|
+
## modern start
|
68
|
+
|
69
|
+
`modern start` 是 `modern dev` 命令的别名,两者的功能和用法完全一致。
|
70
|
+
|
71
|
+
## modern build
|
72
|
+
|
73
|
+
`modern build` 命令默认会在 `dist/` 目录下构建出可用于生产环境的产物。你可以通过修改配置 [`output.distPath`](/configure/app/output/dist-path) 指定产物的输出目录。
|
74
|
+
|
75
|
+
```bash
|
76
|
+
Usage: modern build [options]
|
77
|
+
|
78
|
+
Options:
|
79
|
+
-c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
|
80
|
+
-h, --help 显示命令帮助
|
81
|
+
--analyze 分析构建产物体积,查看各个模块打包后的大小
|
82
|
+
```
|
83
|
+
|
84
|
+
### 分析构建产物体积
|
85
|
+
|
86
|
+
执行 `npx modern build --analyze` 命令,可以在打包生产环境代码的同时,产出一个分析构建产物体积的 HTML 文件:
|
87
|
+
|
88
|
+
```
|
89
|
+
Bundle Analyzer saved report to /example/dist/report.html
|
90
|
+
File sizes after production build:
|
91
|
+
|
92
|
+
122.35 KB dist/static/js/885.1d4fbe5a.js
|
93
|
+
2.3 KB dist/static/js/main.4b8e8d64.js
|
94
|
+
761 B dist/static/js/runtime-main.edb7cf35.js
|
95
|
+
645 B dist/static/css/main.0dd3ecc1.css
|
96
|
+
```
|
97
|
+
|
98
|
+
手动在浏览器中打开上述 HTML 文件,可以看到打包产物的瓦片图,并进行包体积分析和优化:
|
99
|
+
|
100
|
+
<img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/mwa-build-analyze-8784f762c1ab0cb20935829d5f912c4c.png" />
|
101
|
+
|
102
|
+
> 该功能基于 [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) 实现。
|
103
|
+
|
104
|
+
## modern new
|
105
|
+
|
106
|
+
`modern new` 命令用于在已有项目中添加项目元素。
|
107
|
+
|
108
|
+
比如添加应用入口、启用启用一些可选功能如 Tailwind CSS、微前端开发模式等。
|
109
|
+
|
110
|
+
```bash
|
111
|
+
Usage: modern new [options]
|
112
|
+
|
113
|
+
Options:
|
114
|
+
-d, --debug 开启 Debug 模式,打印调试日志信息 (default: false)
|
115
|
+
-c, --config <config> 生成器运行默认配置(JSON 字符串)
|
116
|
+
--dist-tag <tag> 生成器使用特殊的 npm Tag 版本
|
117
|
+
--registry 生成器运行过程中定制 npm Registry
|
118
|
+
-h, --help 显示命令帮助
|
119
|
+
```
|
120
|
+
|
121
|
+
### 添加入口
|
122
|
+
|
123
|
+
在应用工程中,执行 `new` 命令添加入口如下:
|
124
|
+
|
125
|
+
```bash
|
126
|
+
$ npx modern new
|
127
|
+
? 请选择你想要的操作 创建工程元素
|
128
|
+
? 创建工程元素 新建「应用入口」
|
129
|
+
? 请填写入口名称 entry
|
130
|
+
```
|
131
|
+
|
132
|
+
### 启用可选功能
|
133
|
+
|
134
|
+
在应用工程中,执行 `new` 命令启用可选能力如下:
|
135
|
+
|
136
|
+
```bash
|
137
|
+
$ npx modern new
|
138
|
+
? 请选择你想要的操作 启用可选功能
|
139
|
+
? 启用可选功能 (Use arrow keys)
|
140
|
+
❯ 启用 Tailwind CSS 支持
|
141
|
+
启用「BFF」功能
|
142
|
+
启用「微前端」模式
|
143
|
+
启用「单元测试 / 集成测试」功能
|
144
|
+
启用「Visual Testing (Storybook)」模式
|
145
|
+
```
|
146
|
+
|
147
|
+
:::tip
|
148
|
+
`--config` 参数对应参数值需要使用 JSON 字符串。
|
149
|
+
|
150
|
+
pnpm 暂不支持使用 JSON 字符串作为参数值,可使用 `npm new` 开启相关功能。【[相关 Issue](https://github.com/pnpm/pnpm/issues/3876)】
|
151
|
+
|
152
|
+
:::
|
153
|
+
|
154
|
+
## modern serve
|
155
|
+
|
156
|
+
`modern serve` 命令用于在生产环境下启用应用工程, 注意需要提前执行 [`build`](/apis/app/commands#modern-build) 命令构建出对应产物。
|
157
|
+
|
158
|
+
```bash
|
159
|
+
Usage: modern serve [options]
|
160
|
+
|
161
|
+
Options:
|
162
|
+
-c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
|
163
|
+
-h, --help 显示命令帮助
|
164
|
+
--api-only 仅启动 API 接口服务
|
165
|
+
```
|
166
|
+
|
167
|
+
默认情况下,应用将会在 `localhost:8080` 启动,可以通过 `server.port` 修改 Server 端口号:
|
168
|
+
|
169
|
+
```js
|
170
|
+
export default defineConfig({
|
171
|
+
server: {
|
172
|
+
port: 8081,
|
173
|
+
},
|
174
|
+
});
|
175
|
+
```
|
176
|
+
|
177
|
+
## modern upgrade
|
178
|
+
|
179
|
+
在项目根目录下执行命令 `npx modern upgrade`,会默认将当前执行命令项目的 `package.json` 中的 Modern.js 相关依赖更新至最新版本。
|
180
|
+
|
181
|
+
```
|
182
|
+
Usage: modern upgrade [options]
|
183
|
+
|
184
|
+
Options:
|
185
|
+
--registry <registry> 定制 npm registry (default: "")
|
186
|
+
-d,--debug 开启 Debug 模式,打印调试日志信息 (default: false)
|
187
|
+
--cwd <cwd> 项目路径 (default: "")
|
188
|
+
-h, --help display help for command
|
189
|
+
```
|
190
|
+
|
191
|
+
## modern inspect
|
192
|
+
|
193
|
+
`modern inspect` 命令用于查看项目的 [Modern.js Builder 配置](https://modernjs.dev/builder/guide/basic/builder-config.html) 以及 webpack 配置。
|
194
|
+
|
195
|
+
```
|
196
|
+
Usage: modern inspect [options]
|
197
|
+
|
198
|
+
Options:
|
199
|
+
--env <env> 查看指定环境下的配置 (default: "development")
|
200
|
+
--output <output> 指定在 dist 目录下输出的路径 (default: "/")
|
201
|
+
--verbose 在结果中展示函数的完整内容
|
202
|
+
-c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
|
203
|
+
-h, --help 显示命令帮助
|
204
|
+
```
|
205
|
+
|
206
|
+
在项目根目录下执行命令 `npx modern inspect` 后,会在项目的 `dist` 目录生成以下文件:
|
207
|
+
|
208
|
+
- `builder.config.js`: 表示在构建时使用的 Modern.js Builder 配置。
|
209
|
+
- `webpack.config.web.js`: 表示在构建时使用的 webpack 配置。
|
210
|
+
|
211
|
+
```bash
|
212
|
+
➜ npx modern inspect
|
213
|
+
|
214
|
+
Inspect config succeed, open following files to view the content:
|
215
|
+
|
216
|
+
- Builder Config: /root/my-project/dist/builder.config.js
|
217
|
+
- Webpack Config (web): /root/my-project/dist/webpack.config.web.js
|
218
|
+
```
|
219
|
+
|
220
|
+
### 指定环境
|
221
|
+
|
222
|
+
默认情况下,inspect 命令会输出开发环境的配置,你可以添加 `--env production` 选项来输出生产环境的配置:
|
223
|
+
|
224
|
+
```bash
|
225
|
+
modern inspect --env production
|
226
|
+
```
|
227
|
+
|
228
|
+
### 完整内容
|
229
|
+
|
230
|
+
默认情况下,inspect 命令会省略配置对象中的函数内容,你可以添加 `--verbose` 选项来输出函数的完整内容:
|
231
|
+
|
232
|
+
```bash
|
233
|
+
modern inspect --verbose
|
234
|
+
```
|
235
|
+
|
236
|
+
### SSR 构建配置
|
237
|
+
|
238
|
+
如果项目开启了 SSR 能力,则在 `dist` 目录会另外生成一份 `webpack.config.node.js` 文件,对应 SSR 构建时的 webpack 配置。
|
239
|
+
|
240
|
+
```bash
|
241
|
+
➜ npx modern inspect
|
242
|
+
|
243
|
+
Inspect config succeed, open following files to view the content:
|
244
|
+
|
245
|
+
- Builder Config: /root/my-project/dist/builder.config.js
|
246
|
+
- Webpack Config (web): /root/my-project/dist/webpack.config.web.js
|
247
|
+
- Webpack Config (node): /root/my-project/dist/webpack.config.node.js
|
248
|
+
```
|
249
|
+
|
250
|
+
## modern lint
|
251
|
+
|
252
|
+
运行 `ESLint` 进行代码语法检查。
|
253
|
+
|
254
|
+
```bash
|
255
|
+
Usage: modern lint [options] [...files]
|
256
|
+
|
257
|
+
lint and fix source files
|
258
|
+
|
259
|
+
Options:
|
260
|
+
--no-fix disable auto fix source file
|
261
|
+
-h, --help display help for command
|
262
|
+
```
|
263
|
+
|
264
|
+
通常情况下,我们只需要在 `git commit` 阶段通过 `lint-staged` 检查本次提交修改的部分代码。
|
265
|
+
|
266
|
+
- 设置 `--no-fix` 参数后可以关闭自动修复 lint 错误代码的能力。
|
267
|
+
|
268
|
+
## modern test
|
269
|
+
|
270
|
+
`modern test` 命令会自动运行项目下的测试用例。
|
271
|
+
|
272
|
+
```bash
|
273
|
+
Usage: modern test [options]
|
274
|
+
|
275
|
+
Options:
|
276
|
+
-h, --help 显示命令帮助
|
277
|
+
```
|
278
|
+
|
279
|
+
:::tip
|
280
|
+
在使用 `modern test` 命令前,需要先通过 [`new`](/apis/app/commands#modern-new) 命令启用「单元测试 / 集成测试」功能。
|
281
|
+
:::
|
282
|
+
|
283
|
+
效果如下:
|
284
|
+
|
285
|
+
```bash
|
286
|
+
$ npx modern test
|
287
|
+
PASS src/tests/index.test.ts
|
288
|
+
The add method
|
289
|
+
✓ should work fine. (2ms)
|
290
|
+
|
291
|
+
Test Suites: 1 passed, 1 total
|
292
|
+
Tests: 1 passed, 1 total
|
293
|
+
Snapshots: 0 total
|
294
|
+
Time: 0.994 s, estimated 1 s
|
295
|
+
```
|
296
|
+
|
297
|
+
:::info
|
298
|
+
`src` 和 `api` 目录下面的 `*.test.(js|ts)` 文件都会被识别为测试用例。
|
299
|
+
:::
|
@@ -117,7 +117,7 @@ export default const App = ({Component, ...pageProps}:{ Component: React.Compone
|
|
117
117
|
- 页面变化时,保留全局布局的状态
|
118
118
|
- 添加全局样式
|
119
119
|
- ComponentDidCatch 错误处理
|
120
|
-
- 使用
|
120
|
+
- 使用 [defineConfig](/apis/app/runtime/app/define-config) 动态配置运行时配置。
|
121
121
|
|
122
122
|
:::
|
123
123
|
|
@@ -44,15 +44,15 @@ sidebar_position: 2
|
|
44
44
|
```
|
45
45
|
└── routes
|
46
46
|
├── [id]
|
47
|
-
│
|
47
|
+
│ └── page.tsx
|
48
48
|
├── blog
|
49
|
-
│
|
49
|
+
│ └── page.tsx
|
50
50
|
└── page.tsx
|
51
51
|
```
|
52
52
|
|
53
53
|
`routes/[id]/page.tsx` 文件会转为 `/:id` 路由。除了可以确切匹配的 `/blog` 路由,其他所有 `/xxx` 都会匹配到该路由。
|
54
54
|
|
55
|
-
在组件中,可以通过 [useParams](/apis/app/runtime/router
|
55
|
+
在组件中,可以通过 [useParams](/apis/app/runtime/router/router#useparams) 获取对应命名的参数。
|
56
56
|
|
57
57
|
在 loader 中,params 会作为 [loader](/guides/basic-features/data-fetch#loader-函数) 的入参,通过 `params` 的属性可以获取到对应的参数。
|
58
58
|
|