@modern-js/module-tools-docs 2.30.0 → 2.31.0

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/docs/en/api/config/build-config.mdx +49 -49
  3. package/docs/en/api/config/build-preset.mdx +15 -33
  4. package/docs/en/api/config/design-system.md +42 -34
  5. package/docs/en/api/config/plugins.md +3 -3
  6. package/docs/en/api/config/testing.md +2 -2
  7. package/docs/en/api/plugin-api/plugin-hooks.md +24 -24
  8. package/docs/en/components/register-esbuild-plugin.mdx +2 -2
  9. package/docs/en/guide/advance/asset.mdx +8 -27
  10. package/docs/en/guide/advance/build-umd.mdx +18 -66
  11. package/docs/en/guide/advance/external-dependency.mdx +7 -27
  12. package/docs/en/guide/advance/in-depth-about-build.md +4 -4
  13. package/docs/en/guide/advance/in-depth-about-dev-command.md +2 -2
  14. package/docs/en/guide/advance/theme-config.mdx +4 -8
  15. package/docs/en/guide/basic/before-getting-started.md +1 -1
  16. package/docs/en/guide/basic/publish-your-project.md +8 -7
  17. package/docs/en/guide/basic/test-your-project.mdx +10 -47
  18. package/docs/en/guide/basic/use-micro-generator.md +4 -4
  19. package/docs/en/guide/basic/using-storybook.mdx +12 -44
  20. package/docs/en/guide/best-practices/components.mdx +44 -402
  21. package/docs/en/guide/faq/build.mdx +16 -0
  22. package/docs/en/guide/intro/getting-started.md +2 -2
  23. package/docs/en/plugins/guide/getting-started.mdx +8 -24
  24. package/docs/en/plugins/guide/plugin-object.mdx +2 -8
  25. package/docs/en/plugins/official-list/plugin-import.mdx +9 -52
  26. package/docs/en/plugins/official-list/plugin-node-polyfill.md +2 -2
  27. package/docs/zh/api/config/build-config.mdx +52 -52
  28. package/docs/zh/api/config/build-preset.mdx +12 -30
  29. package/docs/zh/api/config/design-system.md +6 -6
  30. package/docs/zh/api/config/plugins.md +3 -3
  31. package/docs/zh/api/config/testing.md +2 -2
  32. package/docs/zh/components/register-esbuild-plugin.mdx +2 -2
  33. package/docs/zh/guide/advance/asset.mdx +9 -30
  34. package/docs/zh/guide/advance/build-umd.mdx +19 -67
  35. package/docs/zh/guide/advance/external-dependency.mdx +8 -28
  36. package/docs/zh/guide/advance/in-depth-about-build.md +4 -4
  37. package/docs/zh/guide/advance/in-depth-about-dev-command.md +2 -2
  38. package/docs/zh/guide/advance/theme-config.mdx +4 -8
  39. package/docs/zh/guide/basic/publish-your-project.md +2 -2
  40. package/docs/zh/guide/basic/test-your-project.mdx +11 -49
  41. package/docs/zh/guide/basic/use-micro-generator.md +4 -4
  42. package/docs/zh/guide/basic/using-storybook.mdx +13 -45
  43. package/docs/zh/guide/best-practices/components.mdx +50 -410
  44. package/docs/zh/guide/faq/build.mdx +16 -0
  45. package/docs/zh/guide/intro/getting-started.md +1 -1
  46. package/docs/zh/plugins/guide/getting-started.mdx +8 -24
  47. package/docs/zh/plugins/guide/plugin-object.mdx +2 -8
  48. package/docs/zh/plugins/official-list/plugin-import.mdx +10 -55
  49. package/docs/zh/plugins/official-list/plugin-node-polyfill.md +2 -2
  50. package/modern.config.ts +1 -12
  51. package/package.json +3 -5
  52. package/theme/index.ts +0 -2
  53. package/theme/index.css +0 -9
@@ -10,7 +10,7 @@ sidebar_position: 6
10
10
 
11
11
  想要使用项目的测试功能,需要确保项目中包含依赖:`"@modern-js/plugin-testing"`,以及按照类似下面的内容进行配置:
12
12
 
13
- ``` ts
13
+ ```ts
14
14
  import { moduleTools, defineConfig } from '@modern-js/module-tools';
15
15
  import { testingPlugin } from '@modern-js/plugin-testing';
16
16
 
@@ -59,31 +59,17 @@ modern test --updateSnapshot
59
59
 
60
60
  对于普通的模块,我们可以按照如下方式使用测试功能:
61
61
 
62
- <CH.Spotlight>
62
+ - 首先是模块的代码:
63
63
 
64
- ```ts ./src/index.ts
64
+ ```ts title="./src/index.ts"
65
65
  export default function () {
66
66
  return 'hello world';
67
67
  }
68
68
  ```
69
69
 
70
- ---
71
-
72
- 首先是模块的代码。
73
-
74
- ```ts ./src/index.ts
75
- export default function () {
76
- return 'hello world';
77
- }
78
- ```
70
+ - 然后在测试文件中,我们可以按以下方式引用,其中 `@` 指向了源码目录,在初始化项目的 `tests/tsconfig.json` 的 `paths` 中定义了。
79
71
 
80
- ---
81
-
82
- 然后在测试文件中,我们可以这样。
83
-
84
- 其中 `@` 指向了源码目录,在初始化项目的 `tests/tsconfig.json` 的 `paths` 中定义了。
85
-
86
- ```ts ./tests/index.test.ts
72
+ ```ts title="./tests/index.test.ts"
87
73
  import main from '@/index';
88
74
 
89
75
  describe('默认值 cases', () => {
@@ -95,9 +81,7 @@ describe('默认值 cases', () => {
95
81
  });
96
82
  ```
97
83
 
98
- ---
99
-
100
- 最后我们可以执行 `modern test`。
84
+ - 最后我们可以执行 `modern test`:
101
85
 
102
86
  ```bash
103
87
  pnpm test
@@ -107,8 +91,6 @@ yarn test
107
91
  npm run test
108
92
  ```
109
93
 
110
- </CH.Spotlight>
111
-
112
94
  ### 组件
113
95
 
114
96
  {/* 链接待补充 */}
@@ -119,21 +101,9 @@ npm run test
119
101
  如果需要使用 Runtime API,那么可以通过 [微生成器](/guide/basic/command-preview) 开启。
120
102
  :::
121
103
 
122
- <CH.Spotlight>
123
-
124
- ```tsx ./src/index.tsx
125
- export const default () {
126
- return (
127
- <div>This is a UI Component</div>
128
- );
129
- }
130
- ```
131
-
132
- ---
104
+ - 首先是组件的代码:
133
105
 
134
- 首先是组件的代码。
135
-
136
- ```tsx ./src/index.tsx
106
+ ```tsx title="./src/index.tsx"
137
107
  export const default () {
138
108
  return (
139
109
  <div>This is a UI Component</div>
@@ -141,13 +111,9 @@ export const default () {
141
111
  }
142
112
  ```
143
113
 
144
- ---
145
-
146
- 然后在测试文件中,我们可以这样。
147
-
148
- 其中 `@` 指向了源码目录,在初始化项目的 `tests/tsconfig.json` 的 `paths` 中定义了。
114
+ - 然后在测试文件中,我们可以按以下方式引用,其中 `@` 指向了源码目录,在初始化项目的 `tests/tsconfig.json` 的 `paths` 中定义了。
149
115
 
150
- ```tsx ./tests/index.test.tsx
116
+ ```tsx title="./tests/index.test.tsx"
151
117
  import { render, screen } from '@modern-js/runtime/testing';
152
118
 
153
119
  import Component from '@/index';
@@ -160,9 +126,7 @@ describe('默认值 cases', () => {
160
126
  });
161
127
  ```
162
128
 
163
- ---
164
-
165
- 最后我们可以执行 `modern test`。
129
+ - 最后我们可以执行 `modern test`。
166
130
 
167
131
  ```bash
168
132
  pnpm test
@@ -171,5 +135,3 @@ yarn test
171
135
  ## or
172
136
  npm run test
173
137
  ```
174
-
175
- </CH.Spotlight>
@@ -20,7 +20,7 @@ sidebar_position: 4
20
20
 
21
21
  :::tip
22
22
  在成功开启后,会提示需要手动在配置中增加如下类似的代码。
23
- ``` ts
23
+ ```ts
24
24
  import { moduleTools, defineConfig } from '@modern-js/module-tools';
25
25
  import { testingPlugin } from '@modern-js/plugin-testing';
26
26
 
@@ -39,7 +39,7 @@ export default defineConfig({
39
39
 
40
40
  :::tip
41
41
  在成功开启后,会提示需要手动在配置中增加如下类似的代码。
42
- ``` ts
42
+ ```ts
43
43
  import { moduleTools, defineConfig } from '@modern-js/module-tools';
44
44
  import { storybookPlugin } from '@modern-js/plugin-storybook';
45
45
 
@@ -67,7 +67,7 @@ export default defineConfig({
67
67
 
68
68
  :::tip
69
69
  在成功开启后,会提示需要手动在配置中增加如下类似的代码。
70
- ``` ts
70
+ ```ts
71
71
  import { moduleTools, defineConfig } from '@modern-js/module-tools';
72
72
  import { tailwindcssPlugin } from '@modern-js/plugin-tailwindcss';
73
73
 
@@ -88,7 +88,7 @@ export default defineConfig({
88
88
 
89
89
  :::tip
90
90
  在成功开启后,会提示需要手动在配置中增加如下类似的代码。
91
- ``` ts
91
+ ```ts
92
92
  import { moduleTools, defineConfig } from '@modern-js/module-tools';
93
93
  import runtime from '@modern-js/runtime/cli';
94
94
 
@@ -34,24 +34,9 @@ Module Tools 集成了 Storybook,因此你几乎可以按照 Storybook 官方
34
34
 
35
35
  ### 引用组件产物
36
36
 
37
- 假如存在 TypeScript 项目 `foo`:
37
+ 假如存在 TypeScript 项目 `foo`,首先要确保 `package.json` 的 `main` 和 `types` 的值为正确的产物路径。
38
38
 
39
- <CH.Spotlight>
40
-
41
- ```json package.json
42
- {
43
- "name": "foo",
44
- "main": "./dist/index.js",
45
- "types": "./dist/types/index.d.ts"
46
- }
47
- ```
48
-
49
- ---
50
-
51
- 确保 `package.json` 的 `main` 和 `types`
52
- 的值为正确的产物路径。
53
-
54
- ```json package.json
39
+ ```json title="package.json"
55
40
  {
56
41
  "name": "foo",
57
42
  "main": "./dist/index.js",
@@ -59,20 +44,15 @@ Module Tools 集成了 Storybook,因此你几乎可以按照 Storybook 官方
59
44
  }
60
45
  ```
61
46
 
62
- ---
63
-
64
- `foo` 项目的源码。
47
+ `foo` 项目的源码:
65
48
 
66
- ```ts src/index.ts
49
+ ```ts title="src/index.ts"
67
50
  export const content = 'hello world';
68
51
  ```
69
52
 
70
- ---
71
-
72
- 确保在 `stories/tsconfig.json` 中设置了指向项目根目录的 `paths` 配置。
73
- `paths` 的 `key` 与项目名称相同,这样在编译过程中以及在代码中不会出现问题。
53
+ 请确保在 `stories/tsconfig.json` 中设置了指向项目根目录的 `paths` 配置。`paths` 的 `key` 与项目名称相同,这样在编译过程中以及在代码中不会出现问题。
74
54
 
75
- ```json stories/tsconfig.json focus=5:7
55
+ ```json title="stories/tsconfig.json"
76
56
  {
77
57
  "extends": "../tsconfig.json",
78
58
  "compilerOptions": {
@@ -88,11 +68,9 @@ export const content = 'hello world';
88
68
  }
89
69
  ```
90
70
 
91
- ---
92
-
93
- 在 Story 代码中直接以项目名称的方式引用。
71
+ 在 Story 代码中直接以项目名称的方式引用:
94
72
 
95
- ```tsx stories/index.stories.tsx focus=1:1
73
+ ```tsx title="stories/index.stories.tsx"
96
74
  import { content } from 'foo';
97
75
 
98
76
  const Component = () => <div>this is a Story Component {content}</div>;
@@ -104,34 +82,24 @@ export default {
104
82
  };
105
83
  ```
106
84
 
107
- ---
108
-
109
- 最后在执行命令的时候,先启动监听模式的源码构建,然后启动 Storybook 调试。
110
-
111
- <CH.Code>
85
+ 最后在执行命令的时候,先启动监听模式的源码构建,然后启动 Storybook 调试即可:
112
86
 
113
- ``` bash terminal-1
87
+ ```bash title="terminal-1"
114
88
  ## 源码构建
115
89
  modern build --watch
116
90
  ```
117
91
 
118
- ---
119
-
120
- ``` bash terminal-2
92
+ ```bash title="terminal-2"
121
93
  ## Storybook 调试
122
94
  modern dev storybook
123
95
  ```
124
96
 
125
- </CH.Code>
126
-
127
- </CH.Spotlight>
128
-
129
97
  :::info
130
98
  在开发过程中,可能会遇到无法实时获得类型定义的情况。因为只有当保存代码后,产物目录下的类型文件才会更新。此时:
131
99
 
132
100
  对于 `pnpm` 的项目,可以按照下面的内容对 `package.json` 进行修改:
133
101
 
134
- ```ts focus=4:7
102
+ ```ts
135
103
  {
136
104
  "name": "foo",
137
105
  "main": "./dist/index.js",
@@ -156,7 +124,7 @@ modern dev storybook
156
124
 
157
125
  引用组件的源码可以通过相对路径的方式:
158
126
 
159
- ```ts ./stories/index.tsx
127
+ ```ts title="./stories/index.tsx"
160
128
  import { content } from '../src';
161
129
 
162
130
  const Component = () => <div>this is a Story Component {content}</div>;