@modern-js/module-tools-docs 2.29.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 +15 -0
  2. package/docs/en/api/config/build-config.mdx +80 -53
  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 +21 -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 +83 -56
  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 +20 -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
@@ -6,7 +6,7 @@ sidebar_position: 3
6
6
 
7
7
  ## 三分钟快速上手
8
8
 
9
- 想要实际体验 Module Tools?首先需要安装 [Node.js LTS](https://github.com/nodejs/Release),并确保 Node 版本大于等于 **14.18.0**。我们推荐使用 Node.js 16 的 LTS 版本。
9
+ 想要实际体验 Module Tools?首先需要安装 [Node.js LTS](https://github.com/nodejs/Release),并确保 Node 版本大于等于 **14.18.0**。我们推荐使用 Node.js 18 的 LTS 版本。
10
10
 
11
11
  ### 创建新项目
12
12
 
@@ -70,6 +70,25 @@ export default defineConfig({
70
70
 
71
71
  如果你的项目存在 `src/index.(js|jsx)` 文件或者同时存在 `src/index.(ts|tsx)` 和 `tsconfig.json` 文件,那么恭喜你可以运行直接运行 `npm run build` 来使用 Module Tools 构建你的项目了。
72
72
 
73
+ ### 核心 npm 包
74
+
75
+ `@modern-js/module-tools` 是 Module Tools 的核心 npm 包,主要提供以下能力:
76
+
77
+ - 提供 `modern dev`, `modern build` 等常用的 CLI 命令。
78
+ - 集成 Modern.js Core,提供配置解析、插件加载等能力。
79
+ - 集成 esbuild 和 SWC,提供构建能力。
80
+ - 集成一些最为常用的插件,比如 `plugin-lint`、`plugin-changeset` 等。
81
+
82
+ `@modern-js/module-tools` 是基于 Modern.js 的插件体系实现的,本质上是一个插件,因此你需要在配置文件的 `plugins` 字段中注册 `moduleTools`:
83
+
84
+ ```ts title="modern.config.ts"
85
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
86
+
87
+ export default defineConfig({
88
+ plugins: [moduleTools()],
89
+ });
90
+ ```
91
+
73
92
  ### 查看官方示例
74
93
 
75
94
  **如果你想要看看使用了模块工程方案的完整项目,可以执行以下命令**:
@@ -8,9 +8,9 @@ sidebar_position: 1
8
8
 
9
9
  我们可以通过下面的例子来快速了解如何编写一个 Module Tools 插件:
10
10
 
11
- <CH.Spotlight>
11
+ 1. 首先我们在初始化的项目下创建 `./plugins/example.ts` 文件。
12
12
 
13
- ```md ./project
13
+ ```md title="./project"
14
14
  ./
15
15
  ├── plugins
16
16
  │ └── example.ts
@@ -18,17 +18,7 @@ sidebar_position: 1
18
18
  └── modern.config.ts
19
19
  ```
20
20
 
21
- ---
22
-
23
- 首先我们在初始化的项目下创建 `./plugins/example.ts` 文件。
24
-
25
- ```md ./project
26
-
27
- ```
28
-
29
- ---
30
-
31
- 接着在 `example.ts` 文件中增加插件的代码。
21
+ 2. 接着在 `example.ts` 文件中增加插件的代码。
32
22
 
33
23
  ```ts
34
24
  import type { CliPlugin, ModuleTools } from '@modern-js/module-tools';
@@ -42,36 +32,30 @@ export const ExamplePlugin = (): CliPlugin<ModuleTools> => {
42
32
  // use hooks
43
33
  afterBuild() {
44
34
  console.info('build over');
45
- }
35
+ },
46
36
  };
47
37
  },
48
38
  };
49
39
  };
50
40
  ```
51
41
 
52
- ---
53
-
54
- 然后我们通过 [`plugins`](/api/config/plugins) API,将刚刚写好的插件进行注册。
42
+ 3. 然后我们通过 [`plugins`](/api/config/plugins) API,将刚刚写好的插件进行注册。
55
43
 
56
- ```ts ./modern.config.ts
44
+ ```ts title="modern.config.ts"
57
45
  import { examplePlugin } from './plugins/example';
58
46
  export default defineConfig({
59
47
  plugins: [examplePlugin()],
60
48
  });
61
49
  ```
62
50
 
63
- ---
64
-
65
- 最后运行 `modern build`,就可以看到。
51
+ 4. 最后运行 `modern build`,就可以看到:
66
52
 
67
- ```bash terminal
53
+ ```bash title="terminal"
68
54
  this is example plugin
69
55
  Build succeed: 510.684ms
70
56
  build over
71
57
  ```
72
58
 
73
- </CH.Spotlight>
74
-
75
59
  通过上面这个例子,我们了解到了下面几件事:
76
60
 
77
61
  - 推荐的插件目录结构
@@ -11,9 +11,7 @@ Module-tools 插件是一个对象,对象包含以下属性:
11
11
 
12
12
  例如在下面的插件代码示例中,在项目开始执行构建任务之前会触发 `beforeBuild` 函数的执行,并打印 `build start` 的 log 内容。
13
13
 
14
- <CH.Code>
15
-
16
- ```ts ./plugins/demo.tsx
14
+ ```ts title="./plugins/demo.tsx"
17
15
  import type { CliPlugin, ModuleTools } from '@modern-js/module-tools';
18
16
 
19
17
  const myPlugin: CliPlugin<ModuleTools> = {
@@ -30,17 +28,13 @@ const myPlugin: CliPlugin<ModuleTools> = {
30
28
  };
31
29
  ```
32
30
 
33
- ---
34
-
35
- ```ts ./modern.config.ts
31
+ ```ts title="modern.config.ts"
36
32
  import { myPlugin } from './plugins/demo';
37
33
  export default {
38
34
  plugins: [myPlugin()],
39
35
  };
40
36
  ```
41
37
 
42
- </CH.Code>
43
-
44
38
  ## 插件类型定义
45
39
 
46
40
  使用 TypeScript 时,可以引入内置的 `CliPlugin` 和 `ModuleTools` 类型,为插件提供正确的类型推导:
@@ -93,81 +93,36 @@ export default defineConfig({
93
93
 
94
94
  简单的函数逻辑其实可以通过模版语言来代替,因此 `customName`,`customStyleName` 等这些配置除了可以传入函数,也可以传入字符串作为模版来代替函数,提高性能。
95
95
 
96
- <CH.Spotlight>
96
+ 我们以这段代码作为示例:
97
97
 
98
98
  ```ts
99
99
  import { MyButton as Btn } from 'foo';
100
100
  ```
101
101
 
102
- ---
103
-
104
- 我们以这段代码进行说明。
102
+ 添加以下配置:
105
103
 
106
104
  ```ts
107
- import { MyButton as Btn } from 'foo';
108
- ```
109
-
110
- ---
111
-
112
- 添加右侧的配置:
113
-
114
- ```ts
115
- import { modulePluginImport } from '@modern-js/plugin-module-import';
116
- import { moduleTools, defineConfig } from '@modern-js/module-tools';
117
-
118
- export default defineConfig({
119
- plugins: [
120
- moduleTools(),
121
- modulePluginImport({
122
- pluginImport: [
123
- {
124
- libraryName: 'foo',
125
- customName: 'foo/es/{{ member }}',
126
- },
127
- ],
128
- }),
129
- ],
130
- });
131
- ```
132
-
133
- ---
134
-
135
- 其中的 `{{ member }}` 会被替换为相应的引入成员
136
-
137
- ```ts focus=8:8
138
- import { modulePluginImport } from '@modern-js/plugin-module-import';
139
- import { moduleTools, defineConfig } from '@modern-js/module-tools';
140
-
141
- export default defineConfig({
142
- plugins: [
143
- moduleTools(),
144
- modulePluginImport({
145
- pluginImport: [
146
- {
147
- libraryName: 'foo',
148
- customName: 'foo/es/{{ member }}',
149
- },
150
- ],
151
- }),
105
+ modulePluginImport({
106
+ pluginImport: [
107
+ {
108
+ libraryName: 'foo',
109
+ customName: 'foo/es/{{ member }}',
110
+ },
152
111
  ],
153
112
  });
154
113
  ```
155
114
 
156
- ---
157
-
158
- 转换后:
115
+ 其中的 `{{ member }}` 会被替换为相应的引入成员,转换后:
159
116
 
160
117
  ```ts
161
118
  import Btn from 'foo/es/MyButton';
162
119
  ```
163
120
 
164
- </CH.Spotlight>
165
-
166
121
  可以看出配置 `customName: "foo/es/{{ member }}"` 的效果等同于配置 `` customName: (member) => `foo/es/${member}` `` ,但是不会有 Node-API 的调用开销。
167
122
 
168
123
  这里使用到的模版是 [handlebars](https://handlebarsjs.com),模版配置中还内置了一些有用的辅助工具,还是以上面的导入语句为例,配置成:
169
124
 
170
- ```ts focus=8:8
125
+ ```ts
171
126
  import { modulePluginImport } from '@modern-js/plugin-module-import';
172
127
  import { moduleTools, defineConfig } from '@modern-js/module-tools';
173
128
 
@@ -52,7 +52,7 @@ type NodePolyfillOptions = {
52
52
 
53
53
  排除要注入的 Node Polyfill。
54
54
 
55
- ``` ts focus=7:9
55
+ ```ts
56
56
  import { moduleTools, defineConfig } from '@modern-js/module-tools';
57
57
  import { modulePluginNodePolyfill } from '@modern-js/plugin-module-node-polyfill';
58
58
 
@@ -70,7 +70,7 @@ export default defineConfig({
70
70
 
71
71
  覆盖内置的 Node Polyfill。
72
72
 
73
- ``` ts focus=7:9
73
+ ```ts
74
74
  import { moduleTools, defineConfig } from '@modern-js/module-tools';
75
75
  import { modulePluginNodePolyfill } from '@modern-js/plugin-module-node-polyfill';
76
76
 
package/modern.config.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  import path from 'path';
2
2
  import { docTools, defineConfig, NavItem } from '@modern-js/doc-tools';
3
- import { remarkCodeHike } from '@code-hike/mdx';
4
3
  import { pluginAutoSidebar } from '@modern-js/doc-plugin-auto-sidebar';
5
4
 
6
- const theme = require('shiki/themes/nord.json');
7
5
  const { version } = require('./package.json');
8
6
 
9
7
  function getI18nHelper(lang: 'zh' | 'en') {
@@ -71,16 +69,7 @@ export default defineConfig({
71
69
  ],
72
70
  markdown: {
73
71
  checkDeadLinks: true,
74
- remarkPlugins: [
75
- [
76
- remarkCodeHike,
77
- {
78
- theme,
79
- autoImport: true,
80
- showCopyButton: true,
81
- },
82
- ],
83
- ],
72
+ experimentalMdxRs: true,
84
73
  },
85
74
  themeConfig: {
86
75
  footer: {
package/package.json CHANGED
@@ -9,15 +9,13 @@
9
9
  "directory": "packages/document/module-doc"
10
10
  },
11
11
  "license": "MIT",
12
- "version": "2.29.0",
12
+ "version": "2.31.0",
13
13
  "main": "index.js",
14
14
  "dependencies": {
15
- "@code-hike/mdx": "^0.7.4",
16
15
  "react": "^18.2.0",
17
16
  "react-dom": "^18.2.0",
18
- "shiki": "^0.11.1",
19
- "@modern-js/doc-plugin-auto-sidebar": "2.29.0",
20
- "@modern-js/doc-tools": "2.29.0"
17
+ "@modern-js/doc-tools": "2.31.0",
18
+ "@modern-js/doc-plugin-auto-sidebar": "2.31.0"
21
19
  },
22
20
  "scripts": {
23
21
  "dev": "modern dev",
package/theme/index.ts CHANGED
@@ -1,4 +1,2 @@
1
- import './index.css';
2
-
3
1
  export * from '@modern-js/doc-tools/theme';
4
2
  export { default } from '@modern-js/doc-tools/theme';
package/theme/index.css DELETED
@@ -1,9 +0,0 @@
1
- @import '@code-hike/mdx/dist/index.css';
2
-
3
- .ch-scrollycoding .header-anchor {
4
- display: none;
5
- }
6
-
7
- .ch-spotlight .header-anchor {
8
- display: none;
9
- }