@modern-js/module-tools-docs 2.45.0 → 2.46.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/docs/en/api/config/build-config.mdx +5 -2
- package/docs/en/guide/advance/in-depth-about-build.md +3 -0
- package/docs/en/guide/basic/before-getting-started.md +1 -1
- package/docs/en/guide/basic/command-preview.md +2 -13
- package/docs/en/guide/basic/use-micro-generator.md +3 -1
- package/docs/en/guide/basic/use-module-doc.mdx +6 -2
- package/docs/en/guide/basic/using-storybook.mdx +11 -0
- package/docs/en/guide/faq/basic.mdx +13 -0
- package/docs/en/guide/faq/build.mdx +18 -11
- package/docs/en/guide/faq/index.md +2 -1
- package/docs/en/guide/intro/getting-started.mdx +1 -1
- package/docs/en/plugins/official-list/plugin-import.mdx +3 -4
- package/docs/zh/api/config/build-config.mdx +5 -2
- package/docs/zh/guide/advance/in-depth-about-build.md +4 -1
- package/docs/zh/guide/basic/before-getting-started.md +1 -1
- package/docs/zh/guide/basic/command-preview.md +1 -12
- package/docs/zh/guide/basic/use-micro-generator.md +3 -2
- package/docs/zh/guide/basic/use-module-doc.mdx +6 -2
- package/docs/zh/guide/basic/using-storybook.mdx +10 -0
- package/docs/zh/guide/faq/basic.mdx +12 -0
- package/docs/zh/guide/faq/build.mdx +18 -14
- package/docs/zh/guide/faq/index.md +4 -3
- package/docs/zh/guide/intro/getting-started.mdx +1 -1
- package/docs/zh/plugins/official-list/plugin-import.mdx +4 -5
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -134,14 +134,17 @@ export default () => <Logo />;
|
|
|
134
134
|
|
|
135
135
|
:::
|
|
136
136
|
|
|
137
|
-
When enabled, the type of svg used can be modified by
|
|
137
|
+
When enabled, the type of svg used can be modified by initing a new declaration file and adding to the `modern-app-env.d.ts`:
|
|
138
138
|
|
|
139
|
-
```ts title="
|
|
139
|
+
```ts title="your-app-env.d.ts"
|
|
140
140
|
declare module '*.svg' {
|
|
141
141
|
const src: React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
|
|
142
142
|
export default src;
|
|
143
143
|
}
|
|
144
|
+
```
|
|
144
145
|
|
|
146
|
+
```ts title="modern-app-env.d.ts"
|
|
147
|
+
/// <reference path='./your-app-env.d.ts' />
|
|
145
148
|
/// <reference types='@modern-js/module-tools/types' />
|
|
146
149
|
```
|
|
147
150
|
|
|
@@ -244,9 +244,12 @@ With `buildType: 'bundleless'`, type files are generated using the project's `ts
|
|
|
244
244
|
|
|
245
245
|
The **Modern.js Module also supports bundling of type files**, although care needs to be taken when using this feature.
|
|
246
246
|
|
|
247
|
+
- Bundle type files does not enable type checking.
|
|
247
248
|
- Some third-party dependencies have incorrect syntax that can cause the bundling process to fail. So in this case, you need to exclude such third-party packages manually with [`buildConfig.externals`](/en/api/config/build-config#externals) or close [dts.respectExternal](/api/config/build-config#dtsrespectexternal) to external all third-party packages types.
|
|
248
249
|
- It is not possible to handle the case where the type file of a third-party dependency points to a `.ts` file. For example, the `package.json` of a third-party dependency contains something like this: `{"types": ". /src/index.ts"}`.
|
|
249
250
|
|
|
251
|
+
For the above problems, our recommended approach is to first use `tsc` to generate d.ts files, then package the index.d.ts as the entry and close `dts.respectExternal`. In the future evolution, we will gradually move towards this handling approach.
|
|
252
|
+
|
|
250
253
|
### Alias Conversion
|
|
251
254
|
|
|
252
255
|
During the bundleless build process, if an alias appears in the source code, e.g.
|
|
@@ -6,7 +6,7 @@ sidebar_position: 1
|
|
|
6
6
|
|
|
7
7
|
## Environment preparation
|
|
8
8
|
|
|
9
|
-
In order to use the Modern.js Module, you first need [NodeJS](https://nodejs.org/zh/) engine, we recommend the latest [LTS version](https://github.com/nodejs/Release), and make sure the Node version is **>=
|
|
9
|
+
In order to use the Modern.js Module, you first need [NodeJS](https://nodejs.org/zh/) engine, we recommend the latest [LTS version](https://github.com/nodejs/Release), and make sure the Node version is **>=16.0.0**. because non-stable NodeJS releases frequently have bugs. You might consider installing via [nvm-windows](https://github.com/coreybutler/nvm-windows) and [nvm](https://github.com/nvm-sh/nvm) (Mac / Linux), so you can easily switch to different NodeJS versions that might be required for different projects that you work on.
|
|
10
10
|
|
|
11
11
|
## Getting Started with npm
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ Usage: modern build [options]
|
|
|
14
14
|
Build module command
|
|
15
15
|
|
|
16
16
|
Options:
|
|
17
|
-
-w, --watch
|
|
17
|
+
-w, --watch Enable watch mode to listen for changes on the fs and automatically rebuild
|
|
18
18
|
--tsconfig [tsconfig] Specify the path to the tsconfig.json file (default:
|
|
19
19
|
". /tsconfig.json")
|
|
20
20
|
--platform [platform] Build artifacts for all or specified platforms
|
|
@@ -24,18 +24,7 @@ Options:
|
|
|
24
24
|
-h, --help Show information about the current command
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
- When wanting to start a build in watch mode, use the `--watch` option.
|
|
30
|
-
- When you want to specify the path to the TypeScript configuration file read by the project build, use `-build --tsconfig . /path/config.json` option. This option overrides all [`buildConfig`](/api/config/build-config) configurations in [`dts.tsconfigPath`](/api/config/build-config).
|
|
31
|
-
- The `-no-dts` option can be used when the DTS type file generation and type checking behavior of the project needs to be turned off. **Note: The generation of type files depends on the results of type checking. If type checking is turned off, then type files will not be generated either**.
|
|
32
|
-
- The `--no-clear` option can be used when the automatic clearing of the output directory needs to be turned off.
|
|
33
|
-
|
|
34
|
-
In addition to the above, Modern.js Module also support `platform` build mode, which can be used to perform build tasks for other tools. For example if you are using module doc plugin, it is currently officially supported to start a doc build task to generate html artifacts by executing the `modern build --platform` or `modern build --platform doc` commands after installing the `@modern-js/plugin-module-doc` plugin.
|
|
35
|
-
|
|
36
|
-
:::tip
|
|
37
|
-
When executing a doc build, if you need to read the build artifacts of the project. Then **don't forget to execute the `modern build` command to ensure the existence of the project's build artifacts before executing the `modern build --platform` command to start the doc build**.
|
|
38
|
-
:::
|
|
27
|
+
Modern.js Module supports the `platform` build mode, which can be used to execute build tasks of other tools. Currently, the official support includes [Rspress](https://rspress.dev/). For example, you can start the doc build task to generate doc products by executing the `modern build --platform` commands.
|
|
39
28
|
|
|
40
29
|
## `modern new`
|
|
41
30
|
|
|
@@ -17,6 +17,7 @@ The microgenerator can be started via [`modern new`](/guide/basic/command-previe
|
|
|
17
17
|
## Develop Module Doc
|
|
18
18
|
|
|
19
19
|
When we want to write documentation for out module project, we can enable the module doc feature. **will create `docs` directory and related files in the project directory, and add `"@modern-js/plugin-rspress"` dependency** in package.json.
|
|
20
|
+
Use `modern dev` and `modern build --platform` to debug and build your doc site.
|
|
20
21
|
|
|
21
22
|
:::tip
|
|
22
23
|
After successfully enabling it, you will be prompted to manually add a code similar to the one below to the configuration.
|
|
@@ -35,6 +36,7 @@ export default defineConfig({
|
|
|
35
36
|
## Test
|
|
36
37
|
|
|
37
38
|
When we want to test some modules, we can enable the test feature. When this feature is enabled, **a `tests` directory and related files will be created in the project directory, and a new `"@modern-js/plugin-testing"` dependency will be added to package.json**.
|
|
39
|
+
Use `edenx test` to run tests.
|
|
38
40
|
|
|
39
41
|
:::tip
|
|
40
42
|
After successfully enabling it, you will be prompted to manually add a code similar to the one below to the configuration.
|
|
@@ -52,7 +54,7 @@ export default defineConfig({
|
|
|
52
54
|
|
|
53
55
|
## Storybook
|
|
54
56
|
|
|
55
|
-
The **Storybook feature** can be enabled when we want to debug a component or a common module. When this feature is enabled, **the `stories` directory and `.storybook` directory are created in the project directory, and a new `"@modern-js/storybook"` dependency is added to package.json**.
|
|
57
|
+
The **Storybook feature** can be enabled when we want to debug a component or a common module. When this feature is enabled, **the `stories` directory and `.storybook` directory are created in the project directory, and a new `"@modern-js/storybook"` dependency is added to package.json**. Use `storybook dev` and `storybook build` to debug and build.
|
|
56
58
|
|
|
57
59
|
## Tailwind CSS Support
|
|
58
60
|
|
|
@@ -403,19 +403,23 @@ type ParseToolOptions = {
|
|
|
403
403
|
|
|
404
404
|
In case of `web`, the component will be rendered directly in the page, otherwise it will be loaded through an iframe.
|
|
405
405
|
|
|
406
|
-
###
|
|
406
|
+
### deprecated: languages
|
|
407
407
|
|
|
408
408
|
:::warning
|
|
409
409
|
Starting from version MAJOR_VERSION.44.0, please refer to the [Internationalization](https://rspress.dev/guide/default-theme/i18n.html) section to implement multiple languages.
|
|
410
410
|
:::
|
|
411
411
|
|
|
412
|
-
###
|
|
412
|
+
### deprecated: useModuleSidebar
|
|
413
413
|
|
|
414
414
|
:::warning
|
|
415
415
|
Starting from version MAJOR_VERSION.44.0, a sniffing mechanism has been implemented internally, so please directly use [\_meta.json](https://rspress.dev/guide/basic/auto-nav-sidebar.html)
|
|
416
416
|
or directly configure [sidebar](https://rspress.dev/api/config/config-theme.html#sidebar) to implement a custom sidebar.
|
|
417
417
|
:::
|
|
418
418
|
|
|
419
|
+
## Scripts
|
|
420
|
+
- `modern dev`: Start dev server for doc site.
|
|
421
|
+
- `modern build --platform`: Build doc site in production, by default output directories is `doc_build`.
|
|
422
|
+
|
|
419
423
|
## Advanced guide
|
|
420
424
|
|
|
421
425
|
The above has covered the basics of developing module documentation, but this is not enough for developing a complete documentation station. Check out the [Rspress](https://rspress.dev) for an in-depth look at our documentation framework.
|
|
@@ -165,6 +165,17 @@ Start Storybook,[detail](https://storybook.js.org/docs/react/api/cli-options#dev
|
|
|
165
165
|
|
|
166
166
|
Build Storybook for production,[detail](https://storybook.js.org/docs/react/api/cli-options#build)
|
|
167
167
|
|
|
168
|
+
## Migrate from V6 to V7
|
|
169
|
+
|
|
170
|
+
Our support methods for the two versions are different, so if you are migrating from V6 to V7,
|
|
171
|
+
we hope you will also use V7 in the same way, while making the following adjustments:
|
|
172
|
+
|
|
173
|
+
- Configuration file: Migrate any custom configurations (if any) in the original `root/config/storybook/main.(j|t)s` to the new `root/.storybook/main.(j|t)s`.
|
|
174
|
+
- Dependencies: Upgrade `@storybook/addon-*` series dependencies (if any) to version 7 and delete `@modern-js/plugin-storybook` dependencies.
|
|
175
|
+
- Commands: Delete the original `edenx dev storybook` and `edenx build --platform` commands.
|
|
176
|
+
If you are used to the original `pnpm run dev` usage, you can replace it with `storybook dev -p 6006` and `storybook build`.
|
|
177
|
+
- modern.config.(j|t)s : Remove the registration of `@modern-js/plugin-storybook` plugin.
|
|
178
|
+
|
|
168
179
|
## V6 (legacy)
|
|
169
180
|
|
|
170
181
|
Starting from `MAJOR_VERSION.40.0` version, `@modern-js/plugin-storybook` will stop iterating. It is recommended to use the V7 version.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# General Questions
|
|
2
|
+
|
|
3
|
+
## What is the relationship between Modern.js Module and Rsbuild?
|
|
4
|
+
|
|
5
|
+
Modern.js Module uses esbuild to build toolkits and component libraries, and Rsbuild focuses on solving web application building scenarios.
|
|
6
|
+
|
|
7
|
+
## Can Modern.js Module use webpack plugins or loaders?
|
|
8
|
+
|
|
9
|
+
Modern.js Module is based on esbuild for building and cannot use tools from the webpack-related ecosystem.
|
|
10
|
+
You can find more community plugins for esbuild [here](https://github.com/esbuild/community-plugins)
|
|
11
|
+
|
|
12
|
+
If the UMD product produced by Modern.js Module does not meet your requirements, you can use Rsbuild and add [UMD Plugin](https://rsbuild.dev/plugins/list/plugin-umd) to build UMD products.
|
|
13
|
+
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Build FAQ
|
|
2
2
|
|
|
3
|
+
Here only some common problems and bad cases are recorded.
|
|
4
|
+
|
|
5
|
+
**If the build products do not meet expectations, especially when [buildPreset](/api/config/build-preset) is configured,
|
|
6
|
+
please first understand what configuration items buildPreset represents, and then check each configuration item based on all configuration items.**
|
|
7
|
+
|
|
3
8
|
## Product FAQ
|
|
4
9
|
|
|
5
10
|
import BuildProductFAQ from '@site-docs-en/components/faq-build-product';
|
|
@@ -200,13 +205,22 @@ module.exports = {
|
|
|
200
205
|
};
|
|
201
206
|
```
|
|
202
207
|
|
|
203
|
-
###
|
|
208
|
+
### Bundleless DTS failed
|
|
204
209
|
|
|
205
|
-
|
|
210
|
+
In the bundleless scenario, it's `tsc` that generates the type declaration file directly. You can find the problem file by printing the error message in the terminal.
|
|
211
|
+
For source code files, it is recommended to fix the type problem, which can better enable reuse of your package. However. if you encounter a type checking problem with a thrid-party package:
|
|
206
212
|
|
|
207
|
-
|
|
213
|
+
1. enable [skipLibCheck](https://www.typescriptlang.org/tsconfig#skipLibCheck) to skip the d.ts check of the thrid-party package.
|
|
214
|
+
2. If the package exports ts files directly, skipLibCheck will not work because it can only skip the d.ts check,
|
|
215
|
+
so you can only turn off [dts.abortOnError](/api/config/build-config.html#dtsabortonerror) to ignore these errors.
|
|
216
|
+
|
|
217
|
+
### Bundle DTS failed
|
|
208
218
|
|
|
209
|
-
|
|
219
|
+
The Modern.js Module directly uses [rollup-plugin-dts](https://github.com/Swatinem/rollup-plugin-dts) to package your type description files.
|
|
220
|
+
**It may not be able to handle the type files of some third-party dependencies**
|
|
221
|
+
|
|
222
|
+
If you encounter an error message titled "Bundle DTS failed" during the build process of the Modern.js Module, you can observe that the error message is from a third-party dependency.
|
|
223
|
+
Try setting [`dts.respectExternal`](/api/config/build-config.html#dtsrespectexternal) to `false` to turn off the behavior of packaging type files of third-party dependencies.
|
|
210
224
|
|
|
211
225
|
### Error reported for `defineConfig` function type: `If there is no reference to "..." then the inferred type of "default" cannot be named`
|
|
212
226
|
|
|
@@ -218,13 +232,6 @@ Check if the [`include`](https://www.typescriptlang.org/tsconfig#include) config
|
|
|
218
232
|
}
|
|
219
233
|
```
|
|
220
234
|
|
|
221
|
-
### Bundleless DTS failed
|
|
222
|
-
|
|
223
|
-
In the bundleless scenario, it's `tsc` that generates the type declaration file directly. You can find the problem file by printing the error message in the terminal. For source code files, it is recommended to fix the type problem, which can better enable reuse of your package. However. if you encounter a type checking problem with a thrid-party package:
|
|
224
|
-
|
|
225
|
-
1. enable [skipLibCheck](https://www.typescriptlang.org/tsconfig#skipLibCheck) to skip the d.ts check of the thrid-party package.
|
|
226
|
-
2. If the package exports ts files directly, skipLibCheck will not work because it can only skip the d.ts check, so you can only turn off [dts.abortOnError](/api/config/build-config.html#dtsabortonerror) to ignore these errors.
|
|
227
|
-
|
|
228
235
|
## Other FAQ
|
|
229
236
|
|
|
230
237
|
import BuildOtherFAQ from '@site-docs-en/components/faq-build-other';
|
|
@@ -6,7 +6,7 @@ sidebar_position: 3
|
|
|
6
6
|
|
|
7
7
|
## 3 minute demo
|
|
8
8
|
|
|
9
|
-
Want to experience Modern.js Module in action? The only prerequisite you need is [Node.js LTS](https://github.com/nodejs/Release) and make sure your Node version is **>=
|
|
9
|
+
Want to experience Modern.js Module in action? The only prerequisite you need is [Node.js LTS](https://github.com/nodejs/Release) and make sure your Node version is **>= 16.0.0**.We recommend using the LTS version of Node.js 18.
|
|
10
10
|
|
|
11
11
|
### Create new project
|
|
12
12
|
|
|
@@ -81,11 +81,10 @@ export default defineConfig({
|
|
|
81
81
|
|
|
82
82
|
[SWC](https://swc.rs/) (Speedy Web Compiler) is written in Rust, and this plugin is based on SWC and ported from [babel-plugin-import](https://github.com/umijs/babel-plugin-import). The configuration options remain consistent.
|
|
83
83
|
|
|
84
|
-
Some configurations can
|
|
84
|
+
Some configurations can be passed in as functions, such as `customName`, `customStyleName`, etc., but in Modern.js Module, we do not recommend using functions in these configuration items.
|
|
85
|
+
Because we will call SWC in the esbuild plugin, and then when Rust calls these configuration functions through Node-API, a deadlock will occur.
|
|
85
86
|
|
|
86
|
-
Simple function logic can be replaced by template language.
|
|
87
|
-
|
|
88
|
-
We will use the following code as example:
|
|
87
|
+
Simple function logic can actually be replaced by template language. Below is an example of using a template with `customName`:
|
|
89
88
|
|
|
90
89
|
```ts
|
|
91
90
|
import { MyButton as Btn } from 'foo';
|
|
@@ -132,14 +132,17 @@ import Logo from './logo.svg';
|
|
|
132
132
|
export default () => <Logo />;
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
|
|
135
|
+
当开启功能后,可以新建一个类型描述文件,并在 `modern-app-env.d.ts` 文件中增加,修改使用 SVG 的类型:
|
|
136
136
|
|
|
137
|
-
```ts title="
|
|
137
|
+
```ts title="your-app-env.d.ts"
|
|
138
138
|
declare module '*.svg' {
|
|
139
139
|
const src: React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
|
|
140
140
|
export default src;
|
|
141
141
|
}
|
|
142
|
+
```
|
|
142
143
|
|
|
144
|
+
```ts title="modern-app-env.d.ts"
|
|
145
|
+
/// <reference path='./your-app-env.d.ts' />
|
|
143
146
|
/// <reference types='@modern-js/module-tools/types' />
|
|
144
147
|
```
|
|
145
148
|
|
|
@@ -244,8 +244,11 @@ export default defineConfig({
|
|
|
244
244
|
|
|
245
245
|
**Modern.js Module 同时还支持对类型文件进行打包**,不过使用该功能的时候需要注意:
|
|
246
246
|
|
|
247
|
+
- 对类型文件进行打包不会开启类型检查。
|
|
247
248
|
- 一些第三方依赖存在错误的语法会导致打包过程失败。因此对于这种情况,需要手动通过 [`buildConfig.externals`](/api/config/build-config#externals) 将这类第三方包排除,或者直接关闭[dts.respectExternal](/api/config/build-config#dtsrespectexternal)从而不打包任何三方包类型。
|
|
248
|
-
- 对于第三方依赖的类型文件指向的是一个 `.ts` 文件的情况,目前无法处理。比如第三方依赖的 `package.json` 中存在这样的内容: `{"types": "./src/index.ts"
|
|
249
|
+
- 对于第三方依赖的类型文件指向的是一个 `.ts` 文件的情况,目前无法处理。比如第三方依赖的 `package.json` 中存在这样的内容: `{"types": "./src/index.ts"`。
|
|
250
|
+
|
|
251
|
+
对于上述问题,我们推荐的处理方式是首先使用 `tsc` 生成 d.ts 文件,然后将 index.d.ts 作为入口进行打包处理,并且关闭 `dts.respectExternal`。在之后的演进我们也会逐渐向这种处理方式靠拢。
|
|
249
252
|
|
|
250
253
|
### 别名转换
|
|
251
254
|
|
|
@@ -6,7 +6,7 @@ sidebar_position: 1
|
|
|
6
6
|
|
|
7
7
|
## 环境准备
|
|
8
8
|
|
|
9
|
-
为了使用 Modern.js Module,首先需要 [NodeJS](https://nodejs.org/zh/),我们推荐最新的[长期维护版本](https://github.com/nodejs/Release),并确保 Node 版本大于等于 **
|
|
9
|
+
为了使用 Modern.js Module,首先需要 [NodeJS](https://nodejs.org/zh/),我们推荐最新的[长期维护版本](https://github.com/nodejs/Release),并确保 Node 版本大于等于 **16.0.0**。因为非稳定的 NodeJS 时常有一些 Bug,你可以使用 [nvm-windows](https://github.com/coreybutler/nvm-windows) 和 [nvm](https://github.com/nvm-sh/nvm)(Mac / Linux)安装,这样你就可以方便地切换到不同的 NodeJS 版本,这些版本可能会用于不同的项目。
|
|
10
10
|
|
|
11
11
|
## 初识 npm
|
|
12
12
|
|
|
@@ -24,18 +24,7 @@ Options:
|
|
|
24
24
|
-h, --help 展示当前命令的信息
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
- 当想要以观察模式启动构建时,使用 `--watch` 选项。
|
|
30
|
-
- 当想要指定项目编译读取的 TypeScript 配置文件的路径时,使用 `build --tsconfig ./path/config.json` 选项。使用该选项后,会覆盖所有 [`buildConfig`](/api/config/build-config) 里 [`dts.tsconfigPath`](/api/config/build-config) 配置。
|
|
31
|
-
- 当需要关闭项目的 DTS 类型文件生成和类型检查行为时,可以使用 `--no-dts` 选项。**注意:类型文件的生成依赖类型检查的结果。如果关闭了类型检查,那么类型文件也不会生成**。
|
|
32
|
-
- 当需要关闭自动清除产物输出目录的行为时,可以使用 `--no-clear` 选项。
|
|
33
|
-
|
|
34
|
-
除了以上方式,Modern.js Module 还支持 `platform` 构建模式,可以用于执行其他工具的构建任务。例如,若使用 doc 插件,官方支持在安装了 `@modern-js/plugin-module-doc` 插件后,可以通过执行 `modern build --platform` 或者 `modern build --platform doc` 命令启动 doc 构建任务生成 doc 产物。
|
|
35
|
-
|
|
36
|
-
:::tip
|
|
37
|
-
在执行 doc 构建的时候,如果需要读取项目的构建产物。那么**在执行 `modern build --platform` 命令启动 doc 构建之前,不要忘记先执行 `modern build` 命令确保项目构建产物的存在**。
|
|
38
|
-
:::
|
|
27
|
+
Modern.js Module 支持 `platform` 构建模式,可以用于执行其他工具的构建任务,目前官方支持的有 [Rspress](https://rspress.dev/)。例如,可以通过执行 `modern build --platform` 命令启动 doc 构建任务生成 doc 产物。
|
|
39
28
|
|
|
40
29
|
## `modern new`
|
|
41
30
|
|
|
@@ -17,6 +17,7 @@ Modern.js Module 提供了微生成器工具,它可以为当前项目:
|
|
|
17
17
|
## 开发模块文档
|
|
18
18
|
|
|
19
19
|
当我们想要为模块编写文档的时候,可以启用模块文档功能。**会在项目目录下创建 `docs` 目录以及相关文件,在 package.json 中新增 `"@modern-js/plugin-rspress"` 依赖**。
|
|
20
|
+
使用 `modern dev` 和 `modern build --platform` 来调试和构建你的文档站点。
|
|
20
21
|
|
|
21
22
|
:::tip
|
|
22
23
|
在成功开启后,会提示需要手动在配置中增加如下类似的代码。
|
|
@@ -34,7 +35,7 @@ export default defineConfig({
|
|
|
34
35
|
|
|
35
36
|
## Test 测试
|
|
36
37
|
|
|
37
|
-
当我们想要对一些模块进行测试的时候,可以启用测试功能。启动该功能后,**会在项目目录下创建 `tests` 目录以及相关文件,在 package.json 中新增 `"@modern-js/plugin-testing"`
|
|
38
|
+
当我们想要对一些模块进行测试的时候,可以启用测试功能。启动该功能后,**会在项目目录下创建 `tests` 目录以及相关文件,在 package.json 中新增 `"@modern-js/plugin-testing"` 依赖**。使用 `modern test` 来测试你的模块。
|
|
38
39
|
|
|
39
40
|
:::tip
|
|
40
41
|
在成功开启后,会提示需要手动在配置中增加如下类似的代码。
|
|
@@ -52,7 +53,7 @@ export default defineConfig({
|
|
|
52
53
|
|
|
53
54
|
## Storybook 调试
|
|
54
55
|
|
|
55
|
-
当我们想要对组件或者普通模块进行调试的时候,可以启用 Storybook 调试功能。启动该功能后,**会在项目目录下创建 `stories` 目录以及 `.storybook` 目录,在 package.json 中新增 `"@modern-js/storybook"`
|
|
56
|
+
当我们想要对组件或者普通模块进行调试的时候,可以启用 Storybook 调试功能。启动该功能后,**会在项目目录下创建 `stories` 目录以及 `.storybook` 目录,在 package.json 中新增 `"@modern-js/storybook"` 依赖**。使用 `storybook dev` 和 `storybook build` 来调试和构建。
|
|
56
57
|
|
|
57
58
|
## Tailwind CSS 支持
|
|
58
59
|
|
|
@@ -399,19 +399,23 @@ type ParseToolOptions = {
|
|
|
399
399
|
|
|
400
400
|
`web`时,代码块内容将会直接渲染在页面中,反之将会通过 iframe 加载。
|
|
401
401
|
|
|
402
|
-
###
|
|
402
|
+
### deprecated: languages
|
|
403
403
|
|
|
404
404
|
:::warning
|
|
405
405
|
从 MAJOR_VERSION.44.0 版本开始,请参考 [国际化](https://rspress.dev/zh/guide/default-theme/i18n.html) 章节来实现多语言。
|
|
406
406
|
:::
|
|
407
407
|
|
|
408
|
-
###
|
|
408
|
+
### deprecated: useModuleSidebar
|
|
409
409
|
|
|
410
410
|
:::warning
|
|
411
411
|
从 MAJOR_VERSION.44.0 版本开始,内部实现了嗅探机制,请直接使用 [_meta.json](https://rspress.dev/zh/guide/basic/auto-nav-sidebar.html)
|
|
412
412
|
或者直接配置 [sidebar](https://rspress.dev/zh/api/config/config-theme.html#sidebar) 来实现自定义侧边栏。
|
|
413
413
|
:::
|
|
414
414
|
|
|
415
|
+
## 命令行
|
|
416
|
+
- `modern dev`: 启动文档站本地开发。
|
|
417
|
+
- `modern build --platform`: 构建生产环境产物。
|
|
418
|
+
|
|
415
419
|
## 进阶指南
|
|
416
420
|
|
|
417
421
|
以上已经介绍完了开发模块文档的基本内容,但是这对于开发一个完整的文档站是不够的。查看[Rspress](https://rspress.dev)以深入了解我们的文档框架。
|
|
@@ -178,6 +178,16 @@ const config = defineConfig({
|
|
|
178
178
|
export default config;
|
|
179
179
|
```
|
|
180
180
|
|
|
181
|
+
## 从 V6 迁移至 V7
|
|
182
|
+
|
|
183
|
+
我们对于两个版本的支持方式不同,因此如果你是从 V6 迁移至 V7 的用户,我们希望你也按上述方式使用 V7,同时做以下调整:
|
|
184
|
+
|
|
185
|
+
- 配置文件:将原来 `root/config/storybook/main.(j|t)s` 里的自定义配置(如果有)迁移到新的 `root/.storybook/main.(j|t)s`。
|
|
186
|
+
- 依赖:升级 `@storybook/addon-*` 系列依赖(如果有)到 7 版本,并删除 `@modern-js/plugin-storybook` 依赖。
|
|
187
|
+
- 命令: 将原来 `edenx dev storybook` 和 `edenx build --platform` 命令删除,如果习惯了原来的 `pnpm run dev` 的调用方式,可以
|
|
188
|
+
将其替换成 `storybook dev -p 6006` 和 `storybook build`。
|
|
189
|
+
- modern.config.(j|t)s : 删除 `@modern-js/plugin-storybook` 插件的注册。
|
|
190
|
+
|
|
181
191
|
## V6 (legacy)
|
|
182
192
|
|
|
183
193
|
从 `MAJOR_VERSION.40.0` 版本开始,`@modern-js/plugin-storybook`将停止迭代。建议使用 V7 版本。
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# 通用类问题
|
|
2
|
+
|
|
3
|
+
## Modern.js Module 和 Rsbuild 的关系?
|
|
4
|
+
|
|
5
|
+
Modern.js Module 使用 esbuild 构建工具库和组件库,Rsbuild 专注于解决 Web 应用构建场景。
|
|
6
|
+
|
|
7
|
+
## Modern.js Module 是否可以使用 webpack plugin 或者 loader?
|
|
8
|
+
|
|
9
|
+
Modern.js Module 基于 esbuild 构建,无法使用 webpack 相关生态的工具。
|
|
10
|
+
[这里](https://github.com/esbuild/community-plugins)可以发现更多 esbuild 社区插件
|
|
11
|
+
|
|
12
|
+
如果 Modern.js Module 生产的 UMD 产物达不到你的要求,可以使用 Rsbuild 并添加 [UMD Plugin](https://rsbuild.dev/zh/plugins/list/plugin-umd) 构建 UMD 产物。
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# 构建相关问题
|
|
2
2
|
|
|
3
|
+
这里只记录了一些常见问题和 bad case。
|
|
4
|
+
|
|
5
|
+
**如果是构建产物不符合预期的场景,尤其是配置了 [buildPreset](/api/config/build-preset) 的情况下,
|
|
6
|
+
请先了解 buildPreset 代表了哪些配置项,再根据所有的配置项逐个检查**
|
|
7
|
+
|
|
3
8
|
## 产物问题
|
|
4
9
|
|
|
5
10
|
import BuildProductFAQ from '@site-docs/components/faq-build-product';
|
|
@@ -193,20 +198,26 @@ module.exports = {
|
|
|
193
198
|
return options;
|
|
194
199
|
});
|
|
195
200
|
},
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
},
|
|
199
204
|
},
|
|
200
205
|
};
|
|
201
206
|
```
|
|
202
207
|
|
|
203
|
-
###
|
|
208
|
+
### Bundleless DTS failed
|
|
209
|
+
|
|
210
|
+
在不打包的场景下,是直接 `tsc` 生成类型声明文件。通过终端打印的错误信息,你可以找到问题文件。对于源码文件,推荐将类型问题进行修复,这能够更好地使你的包得到复用。但如果遇到三方包的类型检查问题:
|
|
204
211
|
|
|
205
|
-
|
|
212
|
+
1. 开启 [skipLibCheck](https://www.typescriptlang.org/tsconfig#skipLibCheck) 来跳过三方包的 d.ts 检查。
|
|
213
|
+
2. 如果三方包直接导出 ts 文件, skipLibCheck 将会失效,因为其只能跳过 d.ts 检查,因此你只能关闭 [dts.abortOnError](/api/config/build-config.html#dtsabortonerror) 来忽略这些错误。
|
|
214
|
+
|
|
215
|
+
### Bundle DTS failed
|
|
206
216
|
|
|
207
|
-
|
|
217
|
+
Modern.js Module 直接使用 [rollup-plugin-dts](https://github.com/Swatinem/rollup-plugin-dts) 来打包你的类型描述文件。
|
|
218
|
+
**它可能无法处理某些第三方依赖的类型文件**。
|
|
208
219
|
|
|
209
|
-
|
|
220
|
+
如果遇到 Modern.js Module 构建过程中出现 `Bundle DTS failed` 的错误信息标题的时候,可以观察报错信息是来自某个第三方依赖。尝试设置 [`dts.respectExternal`](/api/config/build-config.html#dtsrespectexternal) 为 `false` 来关闭打包第三方依赖的类型文件的行为。
|
|
210
221
|
|
|
211
222
|
### `defineConfig` 函数类型报错:`如果没有引用 "...",则无法命名 "default" 的推断类型`
|
|
212
223
|
|
|
@@ -218,13 +229,6 @@ module.exports = {
|
|
|
218
229
|
}
|
|
219
230
|
```
|
|
220
231
|
|
|
221
|
-
### Bundleless DTS failed
|
|
222
|
-
|
|
223
|
-
在不打包的场景下,是直接 `tsc` 生成类型声明文件。通过终端打印的错误信息,你可以找到问题文件。对于源码文件,推荐将类型问题进行修复,这能够更好地使你的包得到复用。但如果遇到三方包的类型检查问题:
|
|
224
|
-
|
|
225
|
-
1. 开启 [skipLibCheck](https://www.typescriptlang.org/tsconfig#skipLibCheck) 来跳过三方包的 d.ts 检查。
|
|
226
|
-
2. 如果三方包直接导出 ts 文件, skipLibCheck 将会失效,因为其只能跳过 d.ts 检查,因此你只能关闭[dts.abortOnError](/api/config/build-config.html#dtsabortonerror)来忽略这些错误。
|
|
227
|
-
|
|
228
232
|
## 其他
|
|
229
233
|
|
|
230
234
|
import BuildOtherFAQ from '@site-docs/components/faq-build-other';
|
|
@@ -6,7 +6,7 @@ sidebar_position: 3
|
|
|
6
6
|
|
|
7
7
|
## 三分钟快速上手
|
|
8
8
|
|
|
9
|
-
想要实际体验 Modern.js Module?首先你需要安装 [Node.js LTS](https://github.com/nodejs/Release),并确保 Node 版本大于等于 **
|
|
9
|
+
想要实际体验 Modern.js Module?首先你需要安装 [Node.js LTS](https://github.com/nodejs/Release),并确保 Node 版本大于等于 **16.0.0**。我们推荐使用 Node.js 18 的 LTS 版本。
|
|
10
10
|
|
|
11
11
|
### 创建新项目
|
|
12
12
|
|
|
@@ -82,11 +82,10 @@ export default defineConfig({
|
|
|
82
82
|
|
|
83
83
|
[SWC](https://swc.rs/) (Speedy Web Compiler) 是基于 Rust 语言编写的,而该插件是基于 SWC,移植自 [babel-plugin-import](https://github.com/umijs/babel-plugin-import),配置选项保持了一致。
|
|
84
84
|
|
|
85
|
-
一些配置可以传入函数,例如 `customName`,`customStyleName`
|
|
85
|
+
一些配置可以传入函数,例如 `customName`,`customStyleName` 等, 但在 Modern.js Module 里,我们不建议在此配置项里使用函数。
|
|
86
|
+
因为我们会在 esbuild 的插件里调用 SWC,然后再当 Rust 通过 Node-API 调用这些配置函数时,会出现死锁现象。
|
|
86
87
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
我们以这段代码作为示例:
|
|
88
|
+
简单的函数逻辑其实可以通过模版语言来代替,下面是一个 `customName` 使用模板的示例:
|
|
90
89
|
|
|
91
90
|
```ts
|
|
92
91
|
import { MyButton as Btn } from 'foo';
|
|
@@ -111,7 +110,7 @@ modulePluginImport({
|
|
|
111
110
|
import Btn from 'foo/es/MyButton';
|
|
112
111
|
```
|
|
113
112
|
|
|
114
|
-
可以看出配置 `customName: "foo/es/{{ member }}"` 的效果等同于配置 `` customName: (member) => `foo/es/${member}` ``
|
|
113
|
+
可以看出配置 `customName: "foo/es/{{ member }}"` 的效果等同于配置 `` customName: (member) => `foo/es/${member}` `` 。
|
|
115
114
|
|
|
116
115
|
这里使用到的模版是 [handlebars](https://handlebarsjs.com),模版配置中还内置了一些有用的辅助工具,还是以上面的导入语句为例,配置成:
|
|
117
116
|
|
package/package.json
CHANGED
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
"directory": "packages/document/module-doc"
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "2.
|
|
12
|
+
"version": "2.46.1",
|
|
13
13
|
"main": "index.js",
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"react": "^18.2.0",
|
|
16
16
|
"react-dom": "^18.2.0",
|
|
17
|
-
"rspress": "1.
|
|
18
|
-
"@rspress/shared": "1.
|
|
19
|
-
"@modern-js/doc-plugin-auto-sidebar": "2.
|
|
17
|
+
"rspress": "1.10.0",
|
|
18
|
+
"@rspress/shared": "1.10.0",
|
|
19
|
+
"@modern-js/doc-plugin-auto-sidebar": "2.46.1"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"dev": "rspress dev",
|