@modern-js/main-doc 2.5.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/en/apis/app/commands.mdx +297 -0
  3. package/en/apis/app/hooks/_category_.json +1 -1
  4. package/en/apis/app/hooks/config/upload.mdx +10 -0
  5. package/en/apis/app/hooks/src/routes.mdx +2 -2
  6. package/en/components/init-app.mdx +5 -5
  7. package/en/configure/app/bff/prefix.mdx +2 -3
  8. package/en/configure/app/bff/proxy.mdx +1 -1
  9. package/en/configure/app/dev/before-start-url.mdx +13 -0
  10. package/en/configure/app/dev/host.mdx +13 -0
  11. package/en/configure/app/output/ssg.mdx +3 -3
  12. package/en/configure/app/runtime/master-app.mdx +1 -1
  13. package/en/configure/app/server/ssr.mdx +18 -0
  14. package/en/configure/app/source/entries-dir.mdx +1 -1
  15. package/en/configure/app/testing/transformer.mdx +1 -1
  16. package/en/configure/app/tools/jest.mdx +1 -1
  17. package/en/guides/advanced-features/rspack-start.mdx +69 -0
  18. package/en/guides/advanced-features/ssg.mdx +8 -8
  19. package/en/guides/advanced-features/ssr.mdx +210 -5
  20. package/en/guides/basic-features/alias.mdx +4 -4
  21. package/en/guides/{css/tailwindcss.mdx → basic-features/css.mdx} +60 -3
  22. package/en/guides/basic-features/data-fetch.mdx +4 -4
  23. package/en/guides/basic-features/env-vars.mdx +4 -0
  24. package/en/guides/basic-features/routes.mdx +23 -7
  25. package/en/guides/concept/builder.mdx +1 -1
  26. package/en/guides/get-started/quick-start.mdx +2 -2
  27. package/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +1 -1
  28. package/en/tutorials/first-app/c03-css.mdx +1 -1
  29. package/en/tutorials/first-app/c07-container.mdx +17 -17
  30. package/en/tutorials/first-app/c08-entries.mdx +23 -23
  31. package/package.json +3 -3
  32. package/scripts/summary.en.json +1 -1
  33. package/scripts/summary.zh.json +1 -1
  34. package/zh/apis/app/commands.mdx +299 -0
  35. package/zh/apis/app/hooks/_category_.json +1 -1
  36. package/zh/apis/app/hooks/config/upload.mdx +12 -2
  37. package/zh/apis/app/hooks/src/routes.mdx +2 -2
  38. package/zh/components/init-app.mdx +5 -5
  39. package/zh/configure/app/bff/prefix.mdx +1 -1
  40. package/zh/configure/app/bff/proxy.mdx +1 -1
  41. package/zh/configure/app/dev/before-start-url.mdx +13 -0
  42. package/zh/configure/app/dev/host.mdx +13 -0
  43. package/zh/configure/app/output/ssg.mdx +3 -3
  44. package/zh/configure/app/server/ssr.mdx +19 -1
  45. package/zh/configure/app/source/entries-dir.mdx +1 -1
  46. package/zh/guides/advanced-features/rspack-start.mdx +69 -0
  47. package/zh/guides/advanced-features/ssg.mdx +8 -8
  48. package/zh/guides/advanced-features/ssr.mdx +213 -6
  49. package/zh/guides/basic-features/alias.mdx +4 -4
  50. package/zh/guides/{css/tailwindcss.mdx → basic-features/css.mdx} +60 -3
  51. package/zh/guides/basic-features/data-fetch.mdx +4 -4
  52. package/zh/guides/basic-features/env-vars.mdx +4 -0
  53. package/zh/guides/basic-features/routes.mdx +23 -7
  54. package/zh/guides/concept/builder.mdx +2 -2
  55. package/zh/guides/get-started/quick-start.mdx +2 -2
  56. package/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +1 -1
  57. package/zh/tutorials/first-app/c03-css.mdx +1 -1
  58. package/zh/tutorials/first-app/c07-container.mdx +17 -17
  59. package/zh/tutorials/first-app/c08-entries.mdx +23 -23
  60. package/en/apis/app/commands/_category_.json +0 -5
  61. package/en/apis/app/commands/build.mdx +0 -39
  62. package/en/apis/app/commands/dev.mdx +0 -61
  63. package/en/apis/app/commands/inspect.mdx +0 -61
  64. package/en/apis/app/commands/lint.mdx +0 -19
  65. package/en/apis/app/commands/new.mdx +0 -55
  66. package/en/apis/app/commands/serve.mdx +0 -27
  67. package/en/apis/app/commands/test.mdx +0 -35
  68. package/en/apis/app/commands/upgrade.mdx +0 -18
  69. package/en/guides/css/_category_.json +0 -5
  70. package/en/guides/css/css-in-js.mdx +0 -40
  71. package/en/guides/css/css-modules.mdx +0 -87
  72. package/en/guides/css/less-sass.mdx +0 -17
  73. package/en/guides/css/postcss.mdx +0 -79
  74. package/zh/apis/app/commands/_category_.json +0 -5
  75. package/zh/apis/app/commands/build.mdx +0 -39
  76. package/zh/apis/app/commands/dev.mdx +0 -61
  77. package/zh/apis/app/commands/inspect.mdx +0 -61
  78. package/zh/apis/app/commands/lint.mdx +0 -19
  79. package/zh/apis/app/commands/new.mdx +0 -54
  80. package/zh/apis/app/commands/serve.mdx +0 -27
  81. package/zh/apis/app/commands/test.mdx +0 -35
  82. package/zh/apis/app/commands/upgrade.mdx +0 -18
  83. package/zh/guides/css/_category_.json +0 -5
  84. package/zh/guides/css/css-in-js.mdx +0 -40
  85. package/zh/guides/css/css-modules.mdx +0 -87
  86. package/zh/guides/css/less-sass.mdx +0 -17
  87. package/zh/guides/css/postcss.mdx +0 -80
@@ -1,61 +0,0 @@
1
- ---
2
- sidebar_position: 1
3
- ---
4
-
5
- # dev / start
6
-
7
- ```bash
8
- Usage: modern dev / modern start [options]
9
-
10
- Development commands
11
-
12
- Options:
13
- -e --entry <entry> compiler by entry
14
- -c --config <config> configuration file path, which can be a relative path or an absolute path
15
- -h, --help show command help
16
- --analyze analyze the bundle and view size of each module
17
- --api-only only start API service
18
- ```
19
-
20
- `modern dev` start a development server,watch file change,default support React Fast Refresh:
21
-
22
- `modern start` is an alias of `modern dev` command, the usage of the two are exactly the same.
23
-
24
- ```bash
25
- $ modern dev
26
-
27
- info Starting dev server...
28
- info App running at:
29
-
30
- > Local: http://localhost:8080/
31
- > Network: http://192.168.0.1:8080/
32
- ```
33
-
34
- ## Compile Partial Pages
35
-
36
- In multi-page (MPA) projects, the `--entry` option can be added to specify one or more pages to compile. In this way, only part of the code in the project will be compiled, and the dev startup speed will be faster.
37
-
38
- For example, execute `modern dev --entry`, the entry selector will be displayed in the command line interface:
39
-
40
- ```bash
41
- $ modern dev --entry
42
-
43
- ? Please select the entry that needs to be built
44
- ❯ ◯ foo
45
- ◯ bar
46
- ◯ baz
47
- ```
48
-
49
- For example, if you select the `foo` entry, only the code related to the `foo` entry will be compiled, and the code of other pages will not be compiled.
50
-
51
- ### Specify the page by parameter
52
-
53
- You can also specify the page name through parameters after `--entry`, and the names of multiple pages can be separated by commas.
54
-
55
- ```bash
56
- # Compile foo page
57
- modern dev --entry foo
58
-
59
- # Compile foo and bar pages
60
- modern dev --entry foo,bar
61
- ```
@@ -1,61 +0,0 @@
1
- ---
2
- sidebar_position: 7
3
- ---
4
- # inspect
5
-
6
- ```
7
- Usage: modern inspect [options]
8
-
9
- Options:
10
- --env <env> view the configuration in the target environment (default: "development")
11
- --output <output> Specify the path to output in the dist (default: "/")
12
- --verbose Show the full function in the result
13
- -c --config <config> configuration file path, which can be a relative path or an absolute path
14
- -h, --help show command help
15
- ```
16
-
17
- `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.
18
-
19
- 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
-
21
- - `builder.config.js`: The Modern.js Builder config to use at build time.
22
- - `webpack.config.web.js`: The webpack config used by to use at build time.
23
-
24
- ```bash
25
- ➜ npx modern inspect
26
-
27
- Inspect config succeed, open following files to view the content:
28
-
29
- - Builder Config: /root/my-project/dist/builder.config.js
30
- - Webpack Config (web): /root/my-project/dist/webpack.config.web.js
31
- ```
32
-
33
- ## Configuration Env
34
-
35
- By default, the inspect command will output the development configs, you can use the `--env production` option to output the production configs:
36
-
37
- ```bash
38
- modern inspect --env production
39
- ```
40
-
41
- ## Verbose content
42
-
43
- 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:
44
-
45
- ```bash
46
- modern inspect --verbose
47
- ```
48
-
49
- ### SSR Configuration
50
-
51
- 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.
52
-
53
- ```bash
54
- ➜ npx modern inspect
55
-
56
- Inspect config succeed, open following files to view the content:
57
-
58
- - Builder Config: /root/my-project/dist/builder.config.js
59
- - Webpack Config (web): /root/my-project/dist/webpack.config.web.js
60
- - Webpack Config (node): /root/my-project/dist/webpack.config.node.js
61
- ```
@@ -1,19 +0,0 @@
1
- ---
2
- sidebar_position: 4
3
- title: lint
4
- ---
5
- # lint
6
-
7
- ```bash
8
- Usage: modern lint [options] [...files]
9
-
10
- lint and fix source files
11
-
12
- Options:
13
- --no-fix disable auto fix source file
14
- -h, --help display help for command
15
- ```
16
-
17
- Run ESLint to check the syntax of the code. Normally, only the part of the code modified by this commit needs to be checked by `lint-staged` during the `git commit` phase.
18
-
19
- - `--no-fix` close auto fix by lint.
@@ -1,55 +0,0 @@
1
- ---
2
- sidebar_position: 2
3
- ---
4
- # new
5
-
6
- ```bash
7
- Usage: modern new [options]
8
-
9
- Execution Generator in App
10
-
11
- Options:
12
- -d, --debug using debug mode to log something (default: false)
13
- -c, --config <config> set default generator config(json string)
14
- --dist-tag <tag> use specified tag version for its generator
15
- --registry set npm registry url to run npm command
16
- -h, --help show command help
17
- ```
18
-
19
- The `modern new` command is used to enable features to an existing project.
20
-
21
- For example, add application entry, enable some optional features such as Tailwind CSS, micro frontend, etc.
22
-
23
- ### Add Entry
24
-
25
- In the project, execute the `new` command to add entries as follows:
26
-
27
- ```bash
28
- $ npx modern new
29
- ? Action Create project element
30
- ? Create project element New "entry"
31
- ? Entry name entry
32
- ```
33
-
34
- ### Enable Features
35
-
36
- In the project, execute the `new` command to enable features as follows:
37
-
38
- ```bash
39
- $ npx modern new
40
- ? Action Enable features
41
- ? Enable features (Use arrow keys)
42
- ❯ Enable Tailwind CSS
43
- Enable BFF
44
- Enable SSG
45
- Enable Micro Frontend
46
- Enable Unit Test / Integration Test
47
- Enable Visual Testing (Storybook)
48
- ```
49
-
50
- :::caution
51
- The `--config` parameter needs to use a JSON string.
52
-
53
- pnpm does not support the use of JSON strings as parameter values currently. Use `npm new` to turn on.【[Relate Issue](https://github.com/pnpm/pnpm/issues/3876)】
54
-
55
- :::
@@ -1,27 +0,0 @@
1
- ---
2
- sidebar_position: 6
3
- ---
4
- # serve
5
-
6
- ```bash
7
- Usage: modern serve [options]
8
-
9
- run server
10
-
11
- Options:
12
- -c --config <config> configuration file path, which can be a relative path or an absolute path
13
- -h, --help show command help
14
- --api-only only run API service
15
- ```
16
-
17
- Usually use the `modern serve` command to enable project run in the production environment, and you need to execute the [`build'](/apis/app/commands/build) command in advance to build the product.
18
-
19
- By default, the project will run in `localhost:8080`, you can modify the Server port number with `server.port`:
20
-
21
- ```js
22
- export default defineConfig({
23
- server: {
24
- port: 8081,
25
- },
26
- });
27
- ```
@@ -1,35 +0,0 @@
1
- ---
2
- sidebar_position: 3
3
- ---
4
- # test
5
-
6
- ```bash
7
- Usage: modern test [options]
8
-
9
- Options:
10
- -h, --help show command help
11
- ```
12
-
13
- :::caution
14
- `modern test` command need to execute the `new` command in advance to enable the `unit test/integration test`.
15
-
16
- :::
17
-
18
- `modern test` command will automatically run the test cases, the effect is as follows:
19
-
20
- ```bash
21
- $ npx modern test
22
- PASS src/tests/index.test.ts
23
- The add method
24
- ✓ should work fine. (2ms)
25
-
26
- Test Suites: 1 passed, 1 total
27
- Tests: 1 passed, 1 total
28
- Snapshots: 0 total
29
- Time: 0.994 s, estimated 1 s
30
- ```
31
-
32
- :::info
33
- files match `*.test.(js|ts)` in `api/` or `src/` will be recognized as test cases by default.
34
-
35
- :::
@@ -1,18 +0,0 @@
1
- ---
2
- sidebar_position: 8
3
- ---
4
- # upgrade
5
-
6
- ```
7
- Usage: modern upgrade [options]
8
-
9
- upgrade Modern.js to latest version.
10
-
11
- Options:
12
- --registry <registry> specify npm registry (default: "")
13
- -d,--debug using debug mode to log something (default: false)
14
- --cwd <cwd> app directory (default: "")
15
- -h, --help show command help
16
- ```
17
-
18
- Execute the command `npx modern upgrade` in the project, by default, dependencies in the `package.json` are updated to the latest version.
@@ -1,5 +0,0 @@
1
- {
2
- "label": "CSS Solutions",
3
- "position": 4,
4
- "collapsed": false
5
- }
@@ -1,40 +0,0 @@
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`](/configure/app/tools/styled-components).
34
-
35
- :::
36
-
37
- :::tip
38
- 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.
39
-
40
- :::
@@ -1,87 +0,0 @@
1
- ---
2
- sidebar_position: 5
3
- ---
4
-
5
- # CSS Modules
6
-
7
- Modern.js out of the box support for [CSS Modules](https://github.com/css-modules/css-modules).
8
-
9
- ## File Suffix Form CSS Modules
10
-
11
- By default, files ending in `.module.(css|scss|sass|less)` are treated as CSS Modules files, for example:
12
-
13
- ```css title="button.module.css"
14
- .redColor {
15
- color: red;
16
- }
17
- ```
18
-
19
- ```js title="Button.jsx"
20
- import styles from './button.module.css';
21
-
22
- export default function Button() {
23
- return (
24
- <button type="button" className={styles.redColor}>
25
- red button
26
- </button>
27
- );
28
- }
29
- ```
30
-
31
- Will eventually be compiled as:
32
-
33
- ```js
34
- <button type="button" className="button_redColor__1-RBg">
35
- red button
36
- </button>
37
- ```
38
-
39
- ## Global CSS Modules
40
-
41
- If you want to remove the `.module` suffix from the filename, you can set [`output.disable CssModuleExtension`](/configure/app/output/disable-css-module-extension).
42
-
43
- After setting, all style files except the style files in the `node_modules/` directory and the file name format of `[name].global.(css|scss|sass|less)` will be processed as CSS Modules.
44
-
45
- If you need global styles at this point, you can solve it by creating a style file with the filename format `[name].global.(css|scss|sass|less)`, for example:
46
-
47
- ```css title="app.global.css"
48
- .bg-blue {
49
- background-color: blue;
50
- }
51
- ```
52
-
53
- ```css title="button.css"
54
- .redColor {
55
- color: red;
56
- }
57
- ```
58
-
59
- ```js title="App.jsx"
60
- import './app.global.css';
61
- import styles from './button.css';
62
-
63
- export default function Button() {
64
- return (
65
- <button type="button" className={`${styles.redColor} bg-blue`}>
66
- button
67
- </button>
68
- );
69
- }
70
- ```
71
-
72
- Will eventually be compiled as:
73
-
74
- ```js
75
- <button type="button" className="button__redColor--JsFYl bg-blue">
76
- button
77
- </button>
78
- ```
79
-
80
- The final effect is as follows:
81
-
82
- ![](https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/more-css-modules.png)
83
-
84
- :::tip
85
- When using [babel-plugin-react-css-modules](https://github.com/gajus/babel-plugin-react-css-modules), it is important to note that the configuration option `generateScopedName` of this plugin needs to be the same as [`output.css ModuleLocalIdentName`](/configure/app/output/css-module-local-ident-name).
86
-
87
- :::
@@ -1,17 +0,0 @@
1
- ---
2
- sidebar_position: 4
3
- ---
4
-
5
- # Less and Sass
6
-
7
- [Less](https://lesscss.org/) and [Sass](https://sass-lang.com/) are two commonly used CSS preprocessors that Modern.js built-in support for the Less and Sass compile capabilities.
8
-
9
- ## Customized Configuration
10
-
11
- - If you need to customize the configuration of [less-loader](https://github.com/webpack-contrib/less-loader), please refer to the [tools.less](/configure/app/tools/less).
12
- - If you need to customize the configuration of [sass-loader](https://github.com/webpack-contrib/sass-loader), please refer to the [tools.less](/configure/app/tools/sass).
13
-
14
- :::tip
15
- CSS files pre-compiled by Less and Sass will still undergo Modern.js build-in [PostCSS](https://postcss.org/) conversion, which has good browser compatibility. For related content, please refer to [[PostCSS](/guides/css/postcss)].
16
-
17
- :::
@@ -1,79 +0,0 @@
1
- ---
2
- sidebar_position: 3
3
- ---
4
-
5
- # PostCSS
6
-
7
- [PostCSS](https://postcss.org/) is a tool for converting CSS code with JavaScript tools and plugins. Modern.js built-in PostCSS and integrates common PostCSS plugins such as [Autoprefixer](https://github.com/postcss/autoprefixer) to meet the style development needs of most projects.
8
-
9
- By default, Modern.js compile and transform CSS as follows:
10
-
11
- 1. [Autoprefixer](https://github.com/postcss/autoprefixer) Automatically add the required browser vendor prefix to CSS rules according to the required browser range. Modern.js default supported browser ranges are: `['> 0.01%', 'not dead', 'not op_mini all']`.
12
-
13
- :::info Note
14
- - [Supported browser range: `> 0.01%`] means that the browser market share is greater than 0.01%.
15
- - `Not dead` means excluding browsers that are no longer officially supported and browsers that have not been updated in the past 24 months.
16
- - `not op_mini all` means exclude Opera Mini.
17
-
18
- :::
19
-
20
- :::info Additional
21
- If you need to modify the default browser support range, you can configure `browserslist` in the project's `package.json` file, and set the rule to refer to the use of [Browserslist](https://github.com/browserslist/browserslist). The following is an example:
22
- `json title ="package.json" { "Browserslist": [ "The last 1 versions", "> 1%", "IE 10" ] } `
23
-
24
- :::
25
-
26
- 2. Provide [CSS custom properties](https://www.w3.org/TR/css-variables-1/) support, you can define and use custom variables in CSS, such as:
27
-
28
- ```css
29
- :root {
30
- --main-bg-color: pink;
31
- }
32
-
33
- body {
34
- background-color: var(--main-bg-color);
35
- }
36
- ```
37
-
38
- 3. Provide [CSS Nesting](https://drafts.csswg.org/css-nesting-1/) support, you can use nested writing in CSS, such as:
39
-
40
- ```css
41
- table.colortable td {
42
- text-align: center;
43
- }
44
- table.colortable td.c {
45
- text-transform: uppercase;
46
- }
47
- ```
48
-
49
- It can also be rewritten as CSS nested:
50
-
51
- ```css
52
- table.colortable {
53
- & td {
54
- text-align: center;
55
- &.c {
56
- text-transform: uppercase;
57
- }
58
- }
59
- }
60
- ```
61
-
62
- 4. Fix known [Flexbugs](https://github.com/philipwalton/flexbugs).
63
- 5. Provide compatibility with the following CSS features:
64
- - [`initial` attribute value](https://developer.mozilla.org/en-US/docs/Web/CSS/initial_value)
65
- - [`break-` attribute](https://developer.mozilla.org/en-US/docs/Web/CSS/break-after)
66
- - [`font-variant`](https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant)
67
- - [Media Query Ranges](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries#syntax_improvements_in_level_4)
68
-
69
- When you need to modify the PostCSS configuration, you can implement it through the underlying configuration [`tools.postcss`](/configure/app/tools/postcss), here is an example:
70
-
71
- ```ts title="modern.config.ts"
72
- export default defineConfig({
73
- tools: {
74
- postcss: {
75
- plugins: ['autoprefixer', ('postcss-flexbugs-fixes': {})],
76
- },
77
- },
78
- });
79
- ```
@@ -1,5 +0,0 @@
1
- {
2
- "label": "命令",
3
- "position": 0,
4
- "collapsed": false
5
- }
@@ -1,39 +0,0 @@
1
- ---
2
- sidebar_position: 5
3
- ---
4
- # build
5
-
6
- ```bash
7
- Usage: modern build [options]
8
-
9
- build application
10
-
11
- Options:
12
- -c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
13
- -h, --help 显示命令帮助
14
- --analyze 分析构建产物体积,查看各个模块打包后的大小
15
- ```
16
-
17
- `modern build` 命令默认会在 `dist/` 目录下构建出可用于生产环境的产物。
18
-
19
- 可以通过修改配置 [`output.distPath`](/configure/app/output/dist-path) 指定产物的输出目录。
20
-
21
- ## 分析构建产物体积
22
-
23
- 执行 `npx modern build --analyze` 命令,可以在打包生产环境代码的同时,产出一个分析构建产物体积的 HTML 文件:
24
-
25
- ```
26
- Bundle Analyzer saved report to /example/dist/report.html
27
- File sizes after production build:
28
-
29
- 122.35 KB dist/static/js/885.1d4fbe5a.js
30
- 2.3 KB dist/static/js/main.4b8e8d64.js
31
- 761 B dist/static/js/runtime-main.edb7cf35.js
32
- 645 B dist/static/css/main.0dd3ecc1.css
33
- ```
34
-
35
- 手动在浏览器中打开上述 HTML 文件,可以看到打包产物的瓦片图,并进行包体积分析和优化:
36
-
37
- <img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/mwa-build-analyze-8784f762c1ab0cb20935829d5f912c4c.png" />
38
-
39
- > 该功能基于 [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) 实现。
@@ -1,61 +0,0 @@
1
- ---
2
- sidebar_position: 1
3
- ---
4
-
5
- # dev / start
6
-
7
- ```bash
8
- Usage: modern dev / modern start [options]
9
-
10
- 本地开发命令
11
-
12
- Options:
13
- -e --entry <entry> 指定入口,只编译特定的页面
14
- -c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
15
- -h, --help 显示命令帮助
16
- --analyze 分析构建产物体积,查看各个模块打包后的大小
17
- --api-only 仅启动 API 接口服务
18
- ```
19
-
20
- `modern dev` 命令用于启动一个本地开发服务器,对源代码进行开发环境编译,同时监听源文件变化,默认支持模块热更新和 React Fast Refresh。
21
-
22
- `modern start` 是 `modern dev` 命令的别名,两者的功能和用法完全一致。
23
-
24
- ```bash
25
- $ modern dev
26
-
27
- info Starting dev server...
28
- info App running at:
29
-
30
- > Local: http://localhost:8080/
31
- > Network: http://192.168.0.1:8080/
32
- ```
33
-
34
- ## 编译部分页面
35
-
36
- 在多页面(MPA)项目中,可以添加 `--entry` 参数来指定编译其中的一个或多个页面。这样可以只编译项目中的部分代码,从而提升 dev 启动速度。
37
-
38
- 比如执行 `modern dev --entry`,在命令行界面中会展示入口选择框:
39
-
40
- ```bash
41
- $ modern dev --entry
42
-
43
- ? 请选择需要构建的入口
44
- ❯ ◯ foo
45
- ◯ bar
46
- ◯ baz
47
- ```
48
-
49
- 比如选择 `foo` 入口,那么只有 `foo` 入口相关的代码会进行编译,其他页面的代码将不会参与构建。
50
-
51
- ### 通过参数指定页面
52
-
53
- 你也可以在 `--entry` 后面通过参数来指定页面名称,多个页面的名称使用逗号分隔。
54
-
55
- ```bash
56
- # 编译 foo 页面
57
- modern dev --entry foo
58
-
59
- # 编译 foo 和 bar 页面
60
- modern dev --entry foo,bar
61
- ```
@@ -1,61 +0,0 @@
1
- ---
2
- sidebar_position: 7
3
- ---
4
- # inspect
5
-
6
- ```
7
- Usage: modern inspect [options]
8
-
9
- Options:
10
- --env <env> 查看指定环境下的配置 (default: "development")
11
- --output <output> 指定在 dist 目录下输出的路径 (default: "/")
12
- --verbose 在结果中展示函数的完整内容
13
- -c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
14
- -h, --help 显示命令帮助
15
- ```
16
-
17
- `modern inspect` 命令,用于查看项目的 [Modern.js Builder 配置](https://modernjs.dev/builder/guide/basic/builder-config.html) 以及 webpack 配置。
18
-
19
- 在项目根目录下执行命令 `npx modern inspect` 后,会在项目的 `dist` 目录生成以下文件:
20
-
21
- - `builder.config.js`: 表示在构建时使用的 Modern.js Builder 配置。
22
- - `webpack.config.web.js`: 表示在构建时使用的 webpack 配置。
23
-
24
- ```bash
25
- ➜ npx modern inspect
26
-
27
- Inspect config succeed, open following files to view the content:
28
-
29
- - Builder Config: /root/my-project/dist/builder.config.js
30
- - Webpack Config (web): /root/my-project/dist/webpack.config.web.js
31
- ```
32
-
33
- ## 指定环境
34
-
35
- 默认情况下,inspect 命令会输出开发环境的配置,你可以添加 `--env production` 选项来输出生产环境的配置:
36
-
37
- ```bash
38
- modern inspect --env production
39
- ```
40
-
41
- ## 完整内容
42
-
43
- 默认情况下,inspect 命令会省略配置对象中的函数内容,你可以添加 `--verbose` 选项来输出函数的完整内容:
44
-
45
- ```bash
46
- modern inspect --verbose
47
- ```
48
-
49
- ## SSR 构建配置
50
-
51
- 如果项目开启了 SSR 能力,则在 `dist` 目录会另外生成一份 `webpack.config.node.js` 文件,对应 SSR 构建时的 webpack 配置。
52
-
53
- ```bash
54
- ➜ npx modern inspect
55
-
56
- Inspect config succeed, open following files to view the content:
57
-
58
- - Builder Config: /root/my-project/dist/builder.config.js
59
- - Webpack Config (web): /root/my-project/dist/webpack.config.web.js
60
- - Webpack Config (node): /root/my-project/dist/webpack.config.node.js
61
- ```