@modern-js/main-doc 2.14.0 → 2.16.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @modern-js/main-doc
2
2
 
3
+ ## 2.16.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 63b3538: fix: dev server crashed when prepare api handler failed
8
+
9
+ fix: 修复更新 api server 报错导致 dev server 退出的问题
10
+
11
+ - fe92de6: fix(builder): browserslist config should not affect node bundles
12
+
13
+ fix(builder): 修复 browserslist 配置会对 node 产物生效的问题
14
+
15
+ - 4e876ab: chore: package.json include the monorepo-relative directory
16
+
17
+ chore: 在 package.json 中声明 monorepo 的子路径
18
+
19
+ - Updated dependencies [fe92de6]
20
+ - Updated dependencies [4e876ab]
21
+ - @modern-js/builder-doc@2.16.0
22
+
23
+ ## 2.15.0
24
+
25
+ ### Patch Changes
26
+
27
+ - @modern-js/builder-doc@2.15.0
28
+
3
29
  ## 2.14.0
4
30
 
5
31
  ### Patch Changes
@@ -0,0 +1,268 @@
1
+ ---
2
+ sidebar_position: 3
3
+ ---
4
+
5
+ # Contributing Guide
6
+
7
+ Thanks for that you are interested in contributing to Modern.js. Before starting your contribution, please take a moment to read the following guidelines.
8
+
9
+ ---
10
+
11
+ ## Setup the Dev Environment
12
+
13
+ ### Fork the Repo
14
+
15
+ [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your
16
+ own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local.
17
+
18
+ ### Install Node.js
19
+
20
+ We recommend using Node.js 16 or 18. You can check your currently used Node.js version with the following command:
21
+
22
+ ```bash
23
+ node -v
24
+ #v16.18.0
25
+ ```
26
+
27
+ If you do not have Node.js installed in your current environment, you can use [nvm](https://github.com/nvm-sh/nvm) or [fnm](https://github.com/Schniz/fnm) to install it.
28
+
29
+ Here is an example of how to install the Node.js 16 LTS version via nvm:
30
+
31
+ ```bash
32
+ # Install the LTS version of Node.js 16
33
+ nvm install 16 --lts
34
+
35
+ # Make the newly installed Node.js 16 as the default version
36
+ nvm alias default 16
37
+
38
+ # Switch to the newly installed Node.js 16
39
+ nvm use 16
40
+ ```
41
+
42
+ ### Install pnpm
43
+
44
+ ```sh
45
+ # Enable pnpm with corepack, only available on Node.js >= `v14.19.0`
46
+ corepack enable
47
+ ```
48
+
49
+ ### Install Dependencies
50
+
51
+ ```sh
52
+ pnpm install
53
+ ```
54
+
55
+ What this will do:
56
+
57
+ - Install all dependencies
58
+ - Create symlinks between packages in the monorepo
59
+ - Run the `prepare` script to build all packages (this will take some time, but is necessary to make ensure all packages are built)
60
+
61
+ > A full rebuild of all packages is generally not required after this. If a new feature you are developing requires an updated version of another package, it is usually sufficient to build the changed dependencies.
62
+
63
+ ### Set Git Email
64
+
65
+ Please make sure you have your email set up in `<https://github.com/settings/emails>`. This will be needed later when you want to submit a pull request.
66
+
67
+ Check that your git client is already configured the email:
68
+
69
+ ```sh
70
+ git config --list | grep email
71
+ ```
72
+
73
+ Set the email to global config:
74
+
75
+ ```sh
76
+ git config --global user.email "SOME_EMAIL@example.com"
77
+ ```
78
+
79
+ Set the email for local repo:
80
+
81
+ ```sh
82
+ git config user.email "SOME_EMAIL@example.com"
83
+ ```
84
+
85
+ ---
86
+
87
+ ## Making Changes and Building
88
+
89
+ Once you have set up the local development environment in your forked repo, we can start development.
90
+
91
+ ### Checkout A New Branch
92
+
93
+ It is recommended to develop on a new branch, as it will make things easier later when you submit a pull request:
94
+
95
+ ```sh
96
+ git checkout -b MY_BRANCH_NAME
97
+ ```
98
+
99
+ ### Build the Package
100
+
101
+ To build the package you want to change, first open the package directory, then run the `build` command:
102
+
103
+ ```sh
104
+ # Replace some-path with the path of the package you want to work on
105
+ cd ./packages/some-path
106
+ pnpm run build
107
+ ```
108
+
109
+ Alternatively, you can build the package from the root directory of the repository using the `--filter` option:
110
+
111
+ ```sh
112
+ pnpm run --filter @modern-js/some-package build
113
+ ```
114
+
115
+ Build all packages:
116
+
117
+ ```sh
118
+ pnpm run prepare
119
+ ```
120
+
121
+ If you need to clean all `node_modules/*` in the project, run the `reset` command:
122
+
123
+ ```sh
124
+ pnpm run reset
125
+ ```
126
+
127
+ ---
128
+
129
+ ## Testing
130
+
131
+ ### Add New Tests
132
+
133
+ If you've fixed a bug or added code that should be tested, then add some tests.
134
+
135
+ You can add unit test cases in the `<PACKAGE_DIR>/tests` folder. The test syntax is based on [Jest](https://jestjs.io/) and [Vitest](https://vitest.dev/).
136
+
137
+ ### Run Unit Tests
138
+
139
+ Before submitting a pull request, it's important to make sure that the changes haven't introduced any regressions or bugs. You can run the unit tests for the project by executing the following command:
140
+
141
+ ```sh
142
+ pnpm run test
143
+ ```
144
+
145
+ Alternatively, you can run the unit tests of single package using the `--filter` option:
146
+
147
+ ```sh
148
+ pnpm run --filter @modern-js/some-package test
149
+ ```
150
+
151
+ ### Run E2E Tests
152
+
153
+ In addition to the unit tests, the Modern.js also includes end-to-end (E2E) tests, which checks the functionality of the application as a whole.
154
+
155
+ You can run the `test:e2e` command to run the E2E tests:
156
+
157
+ ```sh
158
+ pnpm run test:e2e
159
+ ```
160
+
161
+ If you need to run a specified test, you can add keywords to filter:
162
+
163
+ ```sh
164
+ # Only run test cases with the copy-assets keyword
165
+ npx jest copy-assets
166
+ ```
167
+
168
+ ---
169
+
170
+ ## Linting
171
+
172
+ To help maintain consistency and readability of the codebase, we use a ESLint to lint the codes.
173
+
174
+ You can run the Linter by executing the following command:
175
+
176
+ ```sh
177
+ pnpm run lint
178
+ ```
179
+
180
+ ---
181
+
182
+ ## Documentation
183
+
184
+ Currently Modern.js provides documentation in English and Chinese. If you can use Chinese, please update both documents at the same time. Otherwise, just update the English documentation.
185
+
186
+ You can find all the documentation in the `packages/document` folder:
187
+
188
+ ```bash
189
+ root
190
+ └─ packages
191
+ └─ document
192
+ ├─ builder-doc # Documentation for Modern.js Builder
193
+ ├─ doc-tools-doc # Documentation for Modern.js Doc
194
+ ├─ main-doc # Documentation for Modern.js Framework
195
+ └─ module-doc # Documentation for Modern.js Module
196
+ ```
197
+
198
+ This website is built with [Modern.js Doc](https://modernjs.dev/doc-tools), the document content can be written using markdown or mdx syntax. You can refer to the [Modern.js Doc Website](https://modernjs.dev/doc-tools) for detailed usage.
199
+
200
+ The source code of Modern.js Doc can be found in [this folder](https://github.com/web-infra-dev/modern.js/tree/main/packages/solutions/doc-tools).
201
+
202
+ ---
203
+
204
+ ## Submitting Changes
205
+
206
+ ### Add a Changeset
207
+
208
+ Modern.js is using [Changesets](https://github.com/changesets/changesets) to manage the versioning and changelogs.
209
+
210
+ If you've changed some packages, you need add a new changeset for the changes. Please run `change` command to select the changed packages and add the changeset info.
211
+
212
+ ```sh
213
+ pnpm run change
214
+ ```
215
+
216
+ ### Committing your Changes
217
+
218
+ Commit your changes to your forked repo, and [create a pull request](https://help.github.com/articles/creating-a-pull-request/).
219
+
220
+ ### Format of PR titles
221
+
222
+ The format of PR titles follow Conventional Commits.
223
+
224
+ An example:
225
+
226
+ ```
227
+ feat(plugin-swc): Add `xxx` config
228
+ ^ ^ ^
229
+ | | |__ Subject
230
+ | |_______ Scope
231
+ |____________ Type
232
+ ```
233
+
234
+ ---
235
+
236
+ ## Publishing
237
+
238
+ We use **Modern.js Monorepo Solution** to manage version and changelog.
239
+
240
+ Repository maintainers can publish a new version of all packages to npm.
241
+
242
+ Here are the steps to publish (we generally use CI for releases and avoid publishing npm packages locally):
243
+
244
+ 1. Pull latest code from the `main` branch.
245
+ 2. Install:
246
+
247
+ ```sh
248
+ pnpm i
249
+ ```
250
+
251
+ 3. Build packages:
252
+
253
+ ```sh
254
+ pnpm run prepare
255
+ ```
256
+
257
+ 4. Bump version:
258
+
259
+ ```sh
260
+ pnpm run bump
261
+ ```
262
+
263
+ 5. Commit the version change.
264
+
265
+ ```sh
266
+ git add .
267
+ git commit -m "Release va.b.c"
268
+ ```
@@ -0,0 +1,31 @@
1
+ ---
2
+ sidebar_position: 2
3
+ ---
4
+
5
+ # Releases
6
+
7
+ ## Changelog
8
+
9
+ Please visit [GitHub - Releases](https://github.com/web-infra-dev/modern.js/releases) to see what has changed with each release of Modern.js.
10
+
11
+ ## Version Specification
12
+
13
+ Modern.js follows the [Semantic Versioning](https://semver.org) specification.
14
+
15
+ - Major version: Contains incompatible API changes.
16
+ - Minor version: Contains backward compatible functional changes.
17
+ - Patch version: Contains backwards compatible bug fixes
18
+
19
+ ## Release Cycle
20
+
21
+ - Modern.js generally releases an official release every Thursday.
22
+ - If critical bugs appear, we will release a revised version on the same day.
23
+ - We expect to keep Modern.js v2 stable and compatible, there are currently no plans to release the next major version.
24
+
25
+ ## Version Upgrade
26
+
27
+ When you need to upgrade the Modern.js version in your project, you can use the `modern upgrade` command, refer to [Upgrade](/guides/get-started/upgrade).
28
+
29
+ ```bash
30
+ npx modern upgrade
31
+ ```
@@ -0,0 +1,15 @@
1
+ ---
2
+ sidebar_position: 0
3
+ ---
4
+
5
+ # Showcase
6
+
7
+ Welcome to the Modern.js showcase page! Here, we present a collection of websites that have been built using Modern.js.
8
+
9
+ If you have built a website using Modern.js, we would love for you to share it with the community. Simply reply to the GitHub discussion thread with a link to your website. We will collect content on a regular basis and display it on the current page.
10
+
11
+ ## The Cases
12
+
13
+ import { ShowcaseList } from '@site/src/components/ShowcaseList';
14
+
15
+ <ShowcaseList />
@@ -0,0 +1,29 @@
1
+ ---
2
+ sidebar_position: 1
3
+ ---
4
+
5
+ # Meet the Team
6
+
7
+ The development of Modern.js is driven by ByteDance's Modern.js team and community contributors.
8
+
9
+ ## Core Team Members
10
+
11
+ The Modern.js core team members:
12
+
13
+ import { RandomMemberList } from '@site/src/components/RandomMemberList';
14
+
15
+ <RandomMemberList />
16
+
17
+ ## All Contributors
18
+
19
+ Thanks to the following friends for their contributions to Modern.js:
20
+
21
+ <a
22
+ href="https://github.com/web-infra-dev/modern.js/graphs/contributors"
23
+ style={{ display: 'block', marginTop: 24 }}
24
+ >
25
+ <img
26
+ src="https://opencollective.com/modernjs/contributors.svg?width=890&button=false"
27
+ alt="contributors"
28
+ />
29
+ </a>
@@ -0,0 +1,13 @@
1
+ ---
2
+ sidebar_label: disableSvgr
3
+ ---
4
+
5
+ # output.disableSvgr
6
+
7
+ :::tip
8
+ This config is provided by Modern.js Builder, more detail can see [output.disableSvgr](https://modernjs.dev/builder/en/api/config-output.html#outputdisablesvgr).
9
+ :::
10
+
11
+ import Main from '@modern-js/builder-doc/docs/en/config/output/disableSvgr.md';
12
+
13
+ <Main />
@@ -31,7 +31,9 @@ MODERN_ENV priority is higher than NODE_ENV.
31
31
 
32
32
  ### MODERN_TARGET
33
33
 
34
- Auto inject when use `@modern-js/runtime`, Used to distinguish between SSR and CSR environments. Developers can judge by themselves in the code, and dead code will be removed by default when building.
34
+ When using `@modern-js/runtime`, Modern.js will automatically inject `MODERN_TARGET` to distinguish between SSR and CSR environments.
35
+
36
+ You can use `process.env.MODERN_TARGET` to judge the environment and execute the appropriate code.
35
37
 
36
38
  ```ts title="App.tsx"
37
39
  function App() {
@@ -41,9 +43,10 @@ function App() {
41
43
  }
42
44
  ```
43
45
 
44
- In the development environment, you can see that the SSR and CSR bundles as follows:
46
+ After the development build, you can see that the SSR and CSR bundles as follows:
45
47
 
46
48
  ```js title="dist/bundles/main.js"
49
+ // SSR bundles
47
50
  function App() {
48
51
  if (false) {
49
52
  }
@@ -51,6 +54,7 @@ function App() {
51
54
  ```
52
55
 
53
56
  ```js title="dist/static/main.js"
57
+ // CSR bundles
54
58
  function App() {
55
59
  if (true) {
56
60
  console.log(window.innerHeight);
@@ -58,12 +62,16 @@ function App() {
58
62
  }
59
63
  ```
60
64
 
61
- :::note
62
- In a production environment, dead code is removed, such as the `if` statement above.
65
+ This can provide different outputs for different environments to ensure that the bundle size is minimized. It can also be convenient to deal with some side effects for different environments.
63
66
 
64
- :::
67
+ :::note Dead Code Elimination
68
+ In the production environment, minimizers such as Terser and SWC will analyze the code and remove dead code to reduce the bundle size. This process is called "Dead Code Elimination" (DCE).
65
69
 
66
- This can provide different products for different client sides to ensure that the bundle size is minimized. It can also be convenient to deal with some side effects in the code in different environments.
70
+ For example, the code inside the `if (false)` statement will be removed, while the code inside the `if (true)` will be preserved.
71
+
72
+ If you do not use `process.env.MODERN_TARGET` as described above, the code minimizer may not be able to analyze the dead code, resulting in an increased bundle size.
73
+
74
+ :::
67
75
 
68
76
  ## Custom Environment Variables
69
77
 
@@ -0,0 +1,110 @@
1
+ ---
2
+ sidebar_position: 1
3
+ ---
4
+
5
+ # Dependencies FAQ
6
+
7
+ ### How to check the actual installed version of a dependency in the project?
8
+
9
+ You can use the `ls` command that provided by the package manager to view the dependencies version.
10
+
11
+ The following are some basic examples, please refer to the documentation of each package manager for detailed usage.
12
+
13
+ **npm / yarn**
14
+
15
+ For projects using npm or yarn, the `npm ls` command can be used.
16
+
17
+ For example, execute `npm ls @modern-js/core`, you can see the following results:
18
+
19
+ ```
20
+ project
21
+ └─┬ @modern-js/app-tools@2.0.0
22
+ └── @modern-js/core@2.0.0
23
+ ```
24
+
25
+ **pnpm**
26
+
27
+ For projects using pnpm, you can use `pnpm ls` command.
28
+
29
+ For example, execute `pnpm ls @modern-js/core --depth Infinity`, you can see the following results:
30
+
31
+ ```
32
+ devDependencies:
33
+ @modern-js/app-tools 2.0.0
34
+ └── @modern-js/core 2.0.0
35
+ ```
36
+
37
+ ---
38
+
39
+ ### The engine "node" is incompatible when installing dependencies?
40
+
41
+ If the following error message appears when installing dependencies, it means that the version of Node.js used in the current environment is too low, and Node.js needs to be upgraded to a higher version.
42
+
43
+ ```bash
44
+ The engine "node" is incompatible with this module.
45
+
46
+ Expected version ">=14.17.6". Got "12.20.1"
47
+ ```
48
+
49
+ When using Modern.js, it is recommended to use [Node.js 14.x](https://nodejs.org/download/release/latest-v14.x/) or [Node.js 16.x](https://nodejs.org/download/release/latest-v16.x/).
50
+
51
+ If the Node.js version in the current environment is lower than the required version, you can use [nvm](https://github.com/nvm-sh/nvm) or [fnm](https://github.com/Schniz /fnm) and other tools for version switching.
52
+
53
+ Here's an example using nvm:
54
+
55
+ ```
56
+ # Install Node.js v14
57
+ nvm install 14
58
+
59
+ # Switch to Node 14
60
+ nvm use 14
61
+
62
+ # Set Node 14 as the default version
63
+ nvm default 14
64
+ ```
65
+
66
+ It is recommended to use [fnm](https://github.com/Schniz/fnm) in the local development environment. Its usage is similar to nvm, but it has better performance than nvm.
67
+
68
+ ---
69
+
70
+ ### ReactNode type error after upgrading dependencies?
71
+
72
+ If the following types of errors are reported after upgrading the project's dependencies, it means that the wrong `@types/react` version is installed in the project.
73
+
74
+ ```bash
75
+ The types returned by 'render()' are incompatible between these types.
76
+ Type 'React.ReactNode' is not assignable to type 'import("/node_modules/@types/react/index").ReactNode'.
77
+ Type '{}' is not assignable to type 'ReactNode'.
78
+ ```
79
+
80
+ The reason for this problem is that the ReactNode type definitions in React 18 and React 16/17 are different. If there are multiple different `@types/react` versions in the project, there will be a ReactNode type conflict, resulting in the above error.
81
+
82
+ The solution is to lock `@types/react` and `@types/react-dom` in the project to a unified version, such as `v17`.
83
+
84
+ ```json
85
+ {
86
+ "@types/react": "^17",
87
+ "@types/react-dom": "^17"
88
+ }
89
+ ```
90
+
91
+ For the method of locking the dependency version, please refer to [Lock nested dependency](/guides/get-started/upgrade.html#lock-nested-dependency).
92
+
93
+ ---
94
+
95
+ ### After pnpm install, there are some peer dependencies warnings in the console?
96
+
97
+ The reason for this warning is that the version range of peer dependencies declared by some third-party npm packages does not match the version range installed in Modern.js.
98
+
99
+ In most cases, you can ignore the peer dependency warnings because it will not affect the use of Modern.js.
100
+
101
+ ---
102
+
103
+ ### What is the minimum React version supported by the Modern.js framework?
104
+
105
+ The recommended React version for **Modern.js framework is >= 18.0.0**, and different features have different React version requirements.
106
+
107
+ - If you are using React 17, some framework features, such as Steaming SSR, will not be available as they rely on new features provided by React 18.
108
+ - If you're still using React 16, you won't be able to use Modern.js's runtime or server-side featurs. You can consider using Modern.js's build mode, that is, only use Modern.js as a builder. In this case, you can still use React 16.
109
+
110
+ In a future major release of Modern.js, we will remove support for React 16 and React 17. Please upgrade to React 18+ as soon as possible.