@modern-js/module-tools-docs 2.0.0-beta.4

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 (163) hide show
  1. package/LICENSE +144 -0
  2. package/docs/.island/config.ts +245 -0
  3. package/docs/.island/dist/404.html +41 -0
  4. package/docs/.island/dist/assets/before-getting-started.1b82b538.js +87 -0
  5. package/docs/.island/dist/assets/before-getting-started.582a31cc.js +87 -0
  6. package/docs/.island/dist/assets/build-config.72eb0918.js +804 -0
  7. package/docs/.island/dist/assets/build-config.d8bb1658.js +809 -0
  8. package/docs/.island/dist/assets/build-preset.96805d7d.js +256 -0
  9. package/docs/.island/dist/assets/build-preset.c20dcd40.js +256 -0
  10. package/docs/.island/dist/assets/build-your-ui.7f349247.js +2 -0
  11. package/docs/.island/dist/assets/build-your-ui.a8361604.js +2 -0
  12. package/docs/.island/dist/assets/command-preview.2d45fc82.js +264 -0
  13. package/docs/.island/dist/assets/command-preview.dc51b953.js +264 -0
  14. package/docs/.island/dist/assets/components.esm.03560353.js +9 -0
  15. package/docs/.island/dist/assets/design-system.86694ff5.js +1254 -0
  16. package/docs/.island/dist/assets/design-system.c4745cce.js +639 -0
  17. package/docs/.island/dist/assets/dev.1d326a37.js +37 -0
  18. package/docs/.island/dist/assets/dev.1fd06000.js +37 -0
  19. package/docs/.island/dist/assets/down.f35427d3.svg +1 -0
  20. package/docs/.island/dist/assets/extension.12299fd6.js +2 -0
  21. package/docs/.island/dist/assets/extension.96dc63a4.js +2 -0
  22. package/docs/.island/dist/assets/getting-started.40e9218d.js +117 -0
  23. package/docs/.island/dist/assets/getting-started.b1ed3f10.js +114 -0
  24. package/docs/.island/dist/assets/github.3bf8ccee.svg +1 -0
  25. package/docs/.island/dist/assets/index.2b2347ea.js +33 -0
  26. package/docs/.island/dist/assets/index.6cef6f5f.js +4 -0
  27. package/docs/.island/dist/assets/index.cb118238.js +36 -0
  28. package/docs/.island/dist/assets/index.ccb6ce27.js +4 -0
  29. package/docs/.island/dist/assets/island_inject.11a12ecc.js +1 -0
  30. package/docs/.island/dist/assets/island_inject.b13deaee.js +1 -0
  31. package/docs/.island/dist/assets/loading.8c9bb911.svg +1 -0
  32. package/docs/.island/dist/assets/modify-output-product.7f6bff35.js +100 -0
  33. package/docs/.island/dist/assets/modify-output-product.b91eff1f.js +100 -0
  34. package/docs/.island/dist/assets/moon.6b705924.svg +3 -0
  35. package/docs/.island/dist/assets/plugin.895932d8.js +42 -0
  36. package/docs/.island/dist/assets/plugin.d2fbc531.js +42 -0
  37. package/docs/.island/dist/assets/publish-your-project.21b8309f.js +164 -0
  38. package/docs/.island/dist/assets/publish-your-project.8d398b17.js +166 -0
  39. package/docs/.island/dist/assets/right.89674cd7.svg +1 -0
  40. package/docs/.island/dist/assets/search.0aea6901.svg +1 -0
  41. package/docs/.island/dist/assets/search.1c85d17c.js +3 -0
  42. package/docs/.island/dist/assets/search.484eca11.js +222 -0
  43. package/docs/.island/dist/assets/search.54fca8d0.js +3 -0
  44. package/docs/.island/dist/assets/style.09015a4b.css +1 -0
  45. package/docs/.island/dist/assets/style.2e5f7bc2.css +1970 -0
  46. package/docs/.island/dist/assets/sun.841dac10.svg +11 -0
  47. package/docs/.island/dist/assets/test-your-project.18bd4582.js +190 -0
  48. package/docs/.island/dist/assets/test-your-project.f53bebf7.js +190 -0
  49. package/docs/.island/dist/assets/test.0da1f99f.js +67 -0
  50. package/docs/.island/dist/assets/test.0e81f002.js +66 -0
  51. package/docs/.island/dist/assets/translator.b1077c44.svg +1 -0
  52. package/docs/.island/dist/assets/use-micro-generator.7d9e4016.js +60 -0
  53. package/docs/.island/dist/assets/use-micro-generator.db5520c1.js +60 -0
  54. package/docs/.island/dist/assets/using-storybook.57ea6b77.js +260 -0
  55. package/docs/.island/dist/assets/using-storybook.a2212f2e.js +260 -0
  56. package/docs/.island/dist/assets/welcome.0449a9c8.js +13 -0
  57. package/docs/.island/dist/assets/welcome.a8448931.js +13 -0
  58. package/docs/.island/dist/assets/why-module-engineering-solution.6ae8c0e3.js +26 -0
  59. package/docs/.island/dist/assets/why-module-engineering-solution.c9a45cbd.js +26 -0
  60. package/docs/.island/dist/chunk-COLCRJ2V.js +1 -0
  61. package/docs/.island/dist/chunk-K5FMOYDC.js +10 -0
  62. package/docs/.island/dist/chunk-WE42KMYS.js +26 -0
  63. package/docs/.island/dist/client-entry.js +3 -0
  64. package/docs/.island/dist/en/api/build-config.html +344 -0
  65. package/docs/.island/dist/en/api/build-preset.html +82 -0
  66. package/docs/.island/dist/en/api/design-system.html +155 -0
  67. package/docs/.island/dist/en/api/dev.html +45 -0
  68. package/docs/.island/dist/en/api/index.html +41 -0
  69. package/docs/.island/dist/en/api/plugin.html +48 -0
  70. package/docs/.island/dist/en/api/test.html +58 -0
  71. package/docs/.island/dist/en/guide/before-getting-started.html +127 -0
  72. package/docs/.island/dist/en/guide/build-your-ui.html +41 -0
  73. package/docs/.island/dist/en/guide/command-preview.html +100 -0
  74. package/docs/.island/dist/en/guide/extension.html +41 -0
  75. package/docs/.island/dist/en/guide/getting-started.html +76 -0
  76. package/docs/.island/dist/en/guide/modify-output-product.html +140 -0
  77. package/docs/.island/dist/en/guide/publish-your-project.html +91 -0
  78. package/docs/.island/dist/en/guide/test-your-project.html +72 -0
  79. package/docs/.island/dist/en/guide/use-micro-generator.html +65 -0
  80. package/docs/.island/dist/en/guide/using-storybook.html +113 -0
  81. package/docs/.island/dist/en/guide/welcome.html +53 -0
  82. package/docs/.island/dist/en/guide/why-module-engineering-solution.html +49 -0
  83. package/docs/.island/dist/en/index.html +42 -0
  84. package/docs/.island/dist/react-dom.js +1 -0
  85. package/docs/.island/dist/react-dom_client.js +1 -0
  86. package/docs/.island/dist/react.js +1 -0
  87. package/docs/.island/dist/react_jsx-runtime.js +10 -0
  88. package/docs/.island/dist/ssr-manifest.json +57 -0
  89. package/docs/.island/dist/test-result.png +0 -0
  90. package/docs/.island/dist/why-module-solution.png +0 -0
  91. package/docs/.island/dist/zh/api/build-config.html +347 -0
  92. package/docs/.island/dist/zh/api/build-preset.html +82 -0
  93. package/docs/.island/dist/zh/api/design-system.html +149 -0
  94. package/docs/.island/dist/zh/api/dev.html +46 -0
  95. package/docs/.island/dist/zh/api/index.html +41 -0
  96. package/docs/.island/dist/zh/api/plugin.html +48 -0
  97. package/docs/.island/dist/zh/api/test.html +59 -0
  98. package/docs/.island/dist/zh/guide/before-getting-started.html +127 -0
  99. package/docs/.island/dist/zh/guide/build-your-ui.html +41 -0
  100. package/docs/.island/dist/zh/guide/command-preview.html +100 -0
  101. package/docs/.island/dist/zh/guide/extension.html +41 -0
  102. package/docs/.island/dist/zh/guide/getting-started.html +79 -0
  103. package/docs/.island/dist/zh/guide/modify-output-product.html +140 -0
  104. package/docs/.island/dist/zh/guide/publish-your-project.html +92 -0
  105. package/docs/.island/dist/zh/guide/test-your-project.html +72 -0
  106. package/docs/.island/dist/zh/guide/use-micro-generator.html +65 -0
  107. package/docs/.island/dist/zh/guide/using-storybook.html +114 -0
  108. package/docs/.island/dist/zh/guide/welcome.html +53 -0
  109. package/docs/.island/dist/zh/guide/why-module-engineering-solution.html +49 -0
  110. package/docs/.island/dist/zh/index.html +42 -0
  111. package/docs/.island/index.html +39 -0
  112. package/docs/.island/styles/index.css +10 -0
  113. package/docs/en/api/build-config.md +501 -0
  114. package/docs/en/api/build-preset.md +214 -0
  115. package/docs/en/api/design-system.md +524 -0
  116. package/docs/en/api/dev.md +32 -0
  117. package/docs/en/api/index.md +3 -0
  118. package/docs/en/api/plugin.md +34 -0
  119. package/docs/en/api/test.md +48 -0
  120. package/docs/en/guide/advance/asset.mdx +132 -0
  121. package/docs/en/guide/advance/build-umd.mdx +241 -0
  122. package/docs/en/guide/advance/copy.md +235 -0
  123. package/docs/en/guide/advance/external-dependency.mdx +125 -0
  124. package/docs/en/guide/advance/in-depth-about-build.md +266 -0
  125. package/docs/en/guide/advance/in-depth-about-dev-command.md +22 -0
  126. package/docs/en/guide/basic/before-getting-started.md +187 -0
  127. package/docs/en/guide/basic/command-preview.md +204 -0
  128. package/docs/en/guide/basic/modify-output-product.md +145 -0
  129. package/docs/en/guide/basic/publish-your-project.md +115 -0
  130. package/docs/en/guide/basic/test-your-project.mdx +158 -0
  131. package/docs/en/guide/basic/use-micro-generator.md +35 -0
  132. package/docs/en/guide/basic/using-storybook.mdx +187 -0
  133. package/docs/en/guide/intro/getting-started.md +78 -0
  134. package/docs/en/guide/intro/welcome.md +14 -0
  135. package/docs/en/guide/intro/why-module-engineering-solution.md +17 -0
  136. package/docs/en/index.md +35 -0
  137. package/docs/public/test-result.png +0 -0
  138. package/docs/public/why-module-solution.png +0 -0
  139. package/docs/zh/api/build-config.md +570 -0
  140. package/docs/zh/api/build-preset.md +220 -0
  141. package/docs/zh/api/design-system.md +1147 -0
  142. package/docs/zh/api/dev.md +33 -0
  143. package/docs/zh/api/index.md +3 -0
  144. package/docs/zh/api/plugins.md +108 -0
  145. package/docs/zh/api/testing.md +52 -0
  146. package/docs/zh/guide/advance/asset.mdx +132 -0
  147. package/docs/zh/guide/advance/build-umd.mdx +232 -0
  148. package/docs/zh/guide/advance/copy.md +235 -0
  149. package/docs/zh/guide/advance/external-dependency.mdx +125 -0
  150. package/docs/zh/guide/advance/in-depth-about-build.md +267 -0
  151. package/docs/zh/guide/advance/in-depth-about-dev-command.md +26 -0
  152. package/docs/zh/guide/basic/before-getting-started.md +187 -0
  153. package/docs/zh/guide/basic/command-preview.md +204 -0
  154. package/docs/zh/guide/basic/modify-output-product.md +144 -0
  155. package/docs/zh/guide/basic/publish-your-project.md +112 -0
  156. package/docs/zh/guide/basic/test-your-project.mdx +158 -0
  157. package/docs/zh/guide/basic/use-micro-generator.md +35 -0
  158. package/docs/zh/guide/basic/using-storybook.mdx +186 -0
  159. package/docs/zh/guide/intro/getting-started.md +78 -0
  160. package/docs/zh/guide/intro/welcome.md +14 -0
  161. package/docs/zh/guide/intro/why-module-engineering-solution.md +17 -0
  162. package/docs/zh/index.md +29 -0
  163. package/package.json +19 -0
@@ -0,0 +1,158 @@
1
+ # 测试项目
2
+
3
+ 本章将要介绍如何测试可复用模块。
4
+
5
+ ## 先决条件和约定
6
+
7
+ 想要使用项目的测试功能,需要确保项目中包含以下依赖:
8
+
9
+ * `"@modern-js/plugin-testing"`
10
+
11
+ 在模块工程方案中,对于测试用例或者说编写测试的文件有如下约定:
12
+
13
+ * 项目目录下的 `tests` 目录为测试用例和测试文件的目录,**不支持更改运行测试用例的目录**。
14
+ * 默认会自动将后缀为 `.test.[tj]sx?` 的文件识别为测试文件。
15
+ * 其他的 `.[tj]sx?` 后缀的文件被识别为普通的文件,可以用于测试的 `utils` 文件或者其他用途。
16
+
17
+
18
+ ## 运行测试
19
+
20
+ 当准备好了依赖以及了解了测试用例在哪里编写后,我们可以通过以下命令来执行测试:
21
+
22
+ ``` bash
23
+ modern test
24
+
25
+ // 更新 snapshot
26
+ modern test --updateSnapshot
27
+ ```
28
+
29
+ 执行之后,会看到测试的结果:
30
+
31
+ ![test-result](/test-result.png)
32
+
33
+ ## 使用配置
34
+
35
+ 模块工程方案对测试提供了以下配置:
36
+
37
+ * [`testing`](/zh/api/config-test)
38
+
39
+ 可以在 `modern.config.(j|t)s` 中增加它。
40
+
41
+ ## 测试示例
42
+
43
+ ### 普通模块
44
+
45
+ 对于普通的模块,我们可以按照如下方式使用测试功能:
46
+
47
+ <CH.Spotlight>
48
+
49
+ ``` typescript ./src/index.ts
50
+ export default function () {
51
+ return 'hello world';
52
+ }
53
+ ```
54
+
55
+ ---
56
+
57
+ 首先是模块的代码。
58
+
59
+ ``` typescript ./src/index.ts
60
+ export default function () {
61
+ return 'hello world';
62
+ }
63
+ ```
64
+
65
+ ---
66
+
67
+ 然后在测试文件中,我们可以这样。
68
+
69
+ 其中 `@` 指向了源码目录,在初始化项目的 `tests/tsconfig.json` 中定义了。
70
+
71
+ ``` typescript ./tests/index.test.ts
72
+ import main from '@/index';
73
+
74
+ describe('默认值 cases', () => {
75
+ test('Have returns', () => {
76
+ const drink = jest.fn(main);
77
+ drink();
78
+ expect(drink).toHaveReturned();
79
+ });
80
+ });
81
+ ```
82
+
83
+ ---
84
+
85
+ 最后我们可以执行 `modern test`。
86
+
87
+ ``` bash
88
+ pnpm test
89
+ ## or
90
+ yarn test
91
+ ## or
92
+ npm run test
93
+ ```
94
+
95
+ </CH.Spotlight>
96
+
97
+ ### 组件
98
+
99
+ 对于组件,Modern.js 的 [Runtime API](xxx) 提供了用于测试 UI 组件的功能,其功能由 `@modern-js/runtime/testing` 提供。
100
+
101
+ :::tip
102
+ 如果需要使用 Runtime API,那么可以通过 [微生成器](/zh/guide/command-preview) 开启。
103
+ :::
104
+
105
+ <CH.Spotlight>
106
+
107
+ ``` tsx ./src/index.tsx
108
+ export const default () {
109
+ return (
110
+ <div>This is a UI Component</div>
111
+ );
112
+ }
113
+ ```
114
+
115
+ ---
116
+
117
+ 首先是组件的代码。
118
+
119
+ ``` tsx ./src/index.tsx
120
+ export const default () {
121
+ return (
122
+ <div>This is a UI Component</div>
123
+ );
124
+ }
125
+ ```
126
+
127
+ ---
128
+
129
+ 然后在测试文件中,我们可以这样。
130
+
131
+ 其中 `@` 指向了源码目录,在初始化项目的 `tests/tsconfig.json` 中定义了。
132
+
133
+ ``` tsx ./tests/index.test.tsx
134
+ import { render, screen } from '@modern-js/runtime/testing';
135
+
136
+ import Component from '@/index';
137
+
138
+ describe('默认值 cases', () => {
139
+ test('Rendered', () => {
140
+ render(<Component />);
141
+ expect(screen.getByText('This is a UI Component')).toBeInTheDocument();
142
+ });
143
+ });
144
+ ```
145
+
146
+ ---
147
+
148
+ 最后我们可以执行 `modern test`。
149
+
150
+ ``` bash
151
+ pnpm test
152
+ ## or
153
+ yarn test
154
+ ## or
155
+ npm run test
156
+ ```
157
+
158
+ </CH.Spotlight>
@@ -0,0 +1,35 @@
1
+ # 使用微生成器
2
+
3
+ 模块工程解决方案提供了微生成器工具,它可以为当前项目:
4
+
5
+ * 新增目录和文件
6
+ * 修改 `package.json` 文件内容
7
+ * 执行命令
8
+
9
+ 因此通过这些能力,**微生成器可以为项目开启额外的特性功能**。
10
+
11
+ 可以通过 [`modern new`](/zh/guide/command-preview) 启动微生成器。目前模块工程方案支持的微生成器功能有:
12
+
13
+ ## Storybook 调试
14
+
15
+ 当我们想要对组件或者普通模块进行调试的时候,可以启用 **Storybook 调试功能**。启动该功能后,**会在项目目录下创建 `stories` 目录以及相关文件,在 package.json 中新增 `"@modern-js/plugin-storybook"` 依赖**。
16
+
17
+ 关于如何启动 Storybook 以及如何使用 Storybook,可以查看下面的链接:
18
+
19
+ * [`modern dev`](/zh/guide/command-preview#modern-dev)
20
+ * [使用 Storybook](/zh/guide/using-storybook)
21
+
22
+ ## Tailwind CSS 支持
23
+
24
+ 当我们想要为项目增加 [Tailwind CSS](https://v2.tailwindcss.com/) 支持的时候,可以启动这个功能。Tailwind CSS 是一个 CSS 库,提供开箱即用的样式。
25
+
26
+ 关于如何在模块工程里使用 Tailwind CSS,可以查看:
27
+
28
+ * [使用 Tailwind CSS](xxx)
29
+
30
+
31
+ ## 启动 Modern.js Runtime API
32
+
33
+ **Modern.js 提供了 [Runtime API](xxx) 能力,这些 API 只能在 Modern.js 的应用项目环境中使用**。如果你需要开发一个 Modern.js 应用环境中使用的组件,那么你可以开启该特性,微生成器会增加 `"@modern-js/runtime"`依赖。
34
+
35
+ 另外,Storybook 调试工具也会通过检测项目的依赖确定项目是否需要使用 Runtime API,并且提供与 Modern.js 应用项目一样的 Runtime API 运行环境。
@@ -0,0 +1,186 @@
1
+ # 使用 Storybook
2
+
3
+ 首先如果没有看过以下内容的话,可以先花几分钟先了解一下:
4
+
5
+ * [使用微生成器开启 Storybook 调试](/zh/guide/use-micro-generator#storybook-调试)
6
+ * [`modern dev`](/zh/guide/command-preview#modern-dev)
7
+
8
+ [Storybook](https://storybook.js.org/) 是一个专门用于组件调试的工具,围绕着组件开发提供了:
9
+
10
+ * 丰富多样的调试能力
11
+ * 可与一些测试工具结合使用
12
+ * 可重复使用的文档内容
13
+ * 可分享能力
14
+ * 工作流程自动化
15
+
16
+ 因此它是一个复杂且功能强大的工具。
17
+
18
+ 模块工程解决方案集成了 Storybook,因此你几乎可以按照 Storybook 官方文档的内容进行使用。不过依然有一些地方需要注意,接下来讲解一下:
19
+
20
+ ## 调试代码
21
+
22
+ 在调试代码过程中需要引入组件代码,目前可以通过两种方式引入组件代码:
23
+
24
+ * 引用组件产物
25
+ * 引用组件源码
26
+
27
+ 我们更推荐使用第一种“**引用组件产物**”的方式。因为它几乎接近真实的使用场景,不仅可以对组件功能进行调试,同时也对构建产物的正确性进行了验证。
28
+
29
+ 接下来我们分别讲一下这两种方式具体如何使用。
30
+
31
+ ### 引用组件产物
32
+
33
+ 假如存在 TypeScript 项目 `foo`:
34
+
35
+ <CH.Spotlight>
36
+
37
+ ```json package.json
38
+ {
39
+ "name": "foo",
40
+ "main": "./dist/index.js",
41
+ "types": "./dist/types/index.d.ts"
42
+ }
43
+ ```
44
+
45
+ ---
46
+
47
+ 确保 `package.json` 的 `main` 和 `types`
48
+ 的值为真实的路径。
49
+
50
+ ```json package.json
51
+ {
52
+ "name": "foo",
53
+ "main": "./dist/index.js",
54
+ "types": "./dist/types/index.d.ts"
55
+ }
56
+ ```
57
+
58
+ ---
59
+
60
+ `foo` 项目的源码。
61
+
62
+ ```typescript src/index.ts
63
+ export const content = 'hello world';
64
+ ```
65
+
66
+ ---
67
+
68
+ 确保在 `stories/tsconfig.json` 中设置了指向项目根目录的 `paths` 配置。
69
+ `paths` 的 `key` 与项目名称相同。
70
+
71
+ ```json stories/tsconfig.json focus=7:9
72
+ {
73
+ "extends": "../tsconfig.json",
74
+ "include": ["./"],
75
+ "compilerOptions": {
76
+ "jsx": "preserve",
77
+ "baseUrl": ".",
78
+ "paths": {
79
+ "foo": ["../"]
80
+ }
81
+ }
82
+ }
83
+ ```
84
+
85
+ ---
86
+
87
+ 最后在 Story 代码中直接以项目名称的方式引用。
88
+
89
+ ```tsx stories/index.stories.tsx focus=1:1
90
+ import { content } from 'foo';
91
+
92
+ const Component = () => <div>this is a Story Component {content}</div>;
93
+
94
+ export const YourStory = () => <Component />;
95
+
96
+ export default {
97
+ title: 'Your Stories',
98
+ };
99
+ ```
100
+
101
+ </CH.Spotlight>
102
+
103
+ 如果在开发过程中,遇到无法实时获得类型定义的情况,此时:
104
+
105
+ 对于 `pnpm` 的项目,可以按照下面的内容对 `package.json` 进行修改:
106
+
107
+ ``` ts focus=4:7
108
+ {
109
+ "name": "foo",
110
+ "main": "./dist/index.js",
111
+ "types": "./src/index.ts",
112
+ "publishConfig": {
113
+ "types": "./dist/index.d.ts",
114
+ }
115
+ }
116
+ ```
117
+ > 关于 pnpm 的 `publishConfig` 的使用,可以阅读下面这个[链接](https://pnpm.io/package_json#publishconfig)。
118
+
119
+ 而对于 npm 和 Yarn 的项目,则只能通过手动的方式在**开发阶段**和**发布阶段**对 `package.json` 的 `types` 的值进行修改。
120
+
121
+
122
+ 那么为什么可以直接引用产物呢?
123
+
124
+ 1. 在执行 `modern dev storybook` 命令之前,会自动执行 `modern build` 命令,保证项目构建产物的存在。
125
+ 2. 在 Storybook 内部增加了以项目名称作为别名的处理,保证能够**根据 `package.json` 解析出项目的产物路径**。
126
+
127
+
128
+ ### 引用组件源码
129
+
130
+ 引用组件的源码可以通过相对路径的方式:
131
+
132
+ ```ts ./stories/index.tsx
133
+ import { content } from '../src';
134
+
135
+ const Component = () => <div>this is a Story Component {content}</div>;
136
+
137
+ export const YourStory = () => <Component />;
138
+
139
+ export default {
140
+ title: 'Your Stories',
141
+ };
142
+ ```
143
+
144
+ 那么为什么不推荐使用源码的方式呢?
145
+
146
+ 不仅仅是因为使用组件源码无法验证组件产物是否正确,**同时模块工程对于构建产物支持的一些配置无法完全转换为 Storybook
147
+ 内部的配置**。如果某些配置无法进行相互转换的话,就会在 Storybook 调试过程中出现不符合预期的结果。
148
+
149
+ ## 配置 Storybook
150
+
151
+ ### 配置文件
152
+
153
+ Storybook 官方通过一个名为 `.storybook` 的文件夹来进行项目配置,其中包含各种配置文件。**在模块工程方案中,可以在项目的 `config/storybook` 目录下增加 Storybook 配置文件。**
154
+
155
+ 关于 Storybook 各种配置文件的使用方式,可以查看下面的链接:
156
+
157
+ * [Configure Storybook](https://storybook.js.org/docs/react/configure/overview)
158
+
159
+ **不过在模块项目里进行 Storybook 存在一些限制**:
160
+
161
+ * 目前不能修改 Story 文件存放的位置,即无法在 `main.js` 文件里修改 `stories` 配置。
162
+ * 目前不能修改 Webpack 和 Babel 相关的配置,即无法在 `main.js` 文件里修改 `webpackFinal` 和 `babel` 配置。
163
+
164
+ 在未来我们会考虑这些配置是否可以允许修改,不过目前为了减少不可预知的问题暂时限制使用这些配置。
165
+
166
+ ### `dev.storybook`
167
+
168
+ 除了配置文件以外,模块工程方案还在 `modern.config.(j|t)s` 项目配置文件里提供了 `dev.storybook` 配置项。
169
+
170
+ 目前可以通过该配置对 Storybook 的 webpack 配置进行修改。
171
+
172
+ * [`dev.storybook.webpack`](xxx)
173
+
174
+ ### 构建 Storybook 产物
175
+
176
+ 除了可以对组件或者普通的模块进行 Storybook 调试,还可以通过下面的命令来执行 Storybook 的构建任务。
177
+
178
+ ``` bash
179
+ modern build --platform storybook
180
+ ```
181
+
182
+ 关于 `modern build --platform` 命令可以查看:
183
+
184
+ * [`modern build`](/zh/guide/command-preview#modern-build)
185
+
186
+ 构建完成后,可以在 `dist/storybook-static` 目录看到构建产物文件。
@@ -0,0 +1,78 @@
1
+ # 快速开始
2
+
3
+ ## 三分钟快速上手
4
+
5
+ 想要实际体验 Module Tools?首先需要安装 [Node.js LTS](https://github.com/nodejs/Release),并确保 Node 版本大于等于 **14.17.6**。
6
+
7
+ 然后在你的项目里安装以下依赖:
8
+
9
+ - `@modern-js/module-tools`
10
+ - `@modern-js/plugin-testing`
11
+
12
+ > 如果是一个 TypeScript 项目,则需要增加 `"typescript"` 依赖。
13
+
14
+ ```bash
15
+ npm install -D @modern-js/module-tools @modern-js/plugin-testing
16
+ ```
17
+
18
+ > 对于使用 pnpm 或者 Yarn 包管理器的项目,只需要替换 npm 就可以了。**推荐使用 pnpm**。
19
+
20
+ 接着在项目的 `package.json` 文件里增加命令 `"build": "modern build"`:
21
+
22
+ ```json
23
+ {
24
+ "scripts": {
25
+ "build": "modern build"
26
+ }
27
+ }
28
+ ```
29
+
30
+ 如果你的项目存在 `src/index.(js|jsx)` 文件或者同时存在 `src/index.(ts|tsx)` 和 `tsconfig.json` 文件,那么恭喜你可以运行直接运行 `npm run build` 来使用 Module Tools 构建你的项目了。
31
+
32
+ **如果你想要看看使用了模块工程方案的真实项目,可以执行以下命令**:
33
+ ```bash
34
+ git clone https://github.com/modern-js-dev/module-tools-examples
35
+ cd module-tools-example
36
+
37
+ ## 执行构建:
38
+ pnpm build
39
+
40
+ ## 监听模式执行构建:
41
+ pnpm build --watch
42
+
43
+ ## 启动 Storybook
44
+ pnpm dev storybook
45
+
46
+ ## 测试
47
+ pnpm test
48
+ ```
49
+ > 上面的链接对应的内容待补充
50
+
51
+
52
+ **如果你想要创建一个完整的模块工程项目,可以执行以下命令:**
53
+
54
+ ```bash
55
+ npx @modern-js/create your-project-dir-name
56
+ ```
57
+
58
+ 接着在问题交互中,按照如下选择:
59
+
60
+ ```bash
61
+ ? 请选择你想创建的工程类型 模块
62
+ ? 请填写项目名称 library
63
+ ? 请选择开发语言 TS
64
+ ? 请选择包管理工具 pnpm
65
+ ```
66
+ > 项目名称为 `package.json` 中的 `"name"` 字段值。
67
+
68
+ 接着就会开始初始化项目的流程。在项目目录和文件生成以及依赖安装完毕后,此时就创建了一个完整的模块工程项目。
69
+
70
+ 我们可以直接执行 `pnpm build` 命令启动项目的构建,执行 `pnpm build --watch` 命令开启构建的观察模式。
71
+
72
+ ## 让我们开始吧
73
+
74
+ 选择适合你的教程:
75
+
76
+ - 我是初学者,需要学习 Module Tools 的[基础使用](/zh/guide/before-getting-started)。
77
+ - 我已经初步掌握了 Module Tools 的使用,可以学习 Module Tools 的[高级使用](/zh/guide/before-getting-started)。
78
+ - 我是项目的维护者,需要学习如何开发 Module Tools 的插件以及了解更多关于 Module Tools 进阶的内容。
@@ -0,0 +1,14 @@
1
+ # 欢迎使用
2
+
3
+ Module Tools 是 Modern.js 的模块工程解决方案,同时也是核心依赖。它可以让开发者更轻松地构建、调试、发布模块类型的项目。模块类型的项目大多数情况可以认为是 npm 包类型的项目,它可能是一个组件、组件库或者工具库项目。
4
+
5
+ 如果你正打算开发一个 npm 包类型的项目,那么你就来对地方了!Modern.js 提供了专业的模块工程解决方案。它带来了:
6
+
7
+ - **简单的项目初始化**:仅需执行 `npx @modern-js/create project-dir` 命令,然后进行几个交互问题,就可以创建一个完整的模块类型项目。创建的项目还支持选择 [**pnpm**](https://pnpm.io/)、[**Yarn**](https://classic.yarnpkg.com/) 两种包管理器。
8
+ - **代码格式化**:在模块工程项目中,你可以执行 `modern lint` 来对代码进行格式化。同时初始化的模块工程项目里包含了 Modern.js 的 [ESLint](https://eslint.org/docs/latest/user-guide/core-concepts#what-is-eslint) 规则集,可以满足大部分场景下的需求。
9
+ - **全面的构建能力和更快的构建速度**:Module Tools 基于 [esbuild](https://esbuild.github.io/getting-started/) 和 [SWC](https://swc.rs/) 提供了高性能的构建能力,并且为不同构建模块的场景提供了丰富的配置。
10
+ - **Storybook 调试工具**:Module Tools 为调试模块项目提供了 [Storybook](https://storybook.js.org/) 调试工具。在安装了 Module Tools 的 Storybook 插件后,你可以使用 `modern dev storybook` 命令来启动它。你不仅可以使用 Storybook 对组件进行调试,也可以使用在其他类型的模块上。
11
+ - **集成 Jest 的测试能力**:在需要对模块测试的时候,可以使用 Module Tools 的 `modern test` 命令。Module Tools 不仅集成了 [Jest](https://jestjs.io/),同时也提供了配置 [Jest](https://jestjs.io/docs/configuration) 的 API。
12
+ - **基于 Changesets 实现的版本管理**:当需要对项目记录变更内容的时候,可以使用 `modern change` 命令生成包含变更内容的 Markdown 文件;当需要对项目进行版本升级的时候,可以使用 `modern bump` 命令通过 Markdown 文件分析并升级版本;当需要发布项目的时候,可以使用 `modern release` 命令对项目进行发布。Module Tools 基于 [Changesets](https://github.com/changesets/changesets) 实现了这些命令。
13
+ - **可扩展性的插件机制**:想要为项目集成其他的调试工具?又或者是想要在构建过程中做一些额外处理?Module Tools 提供了插件机制和插件钩子,插件钩子覆盖了 `dev` 命令和 `build` 命令两个流程。你可以通过它们为项目进行能力的扩展。
14
+ - **还有更多**:Module Tools 在未来还会不断的在构建、调试功能上进行优化。如果在模块项目构建上存在需要解决的重要问题,又或者是某个主流的模块项目调试工具、模式出现的时候,那么它们很可能成为 Module Tools 将要支持功能。
@@ -0,0 +1,17 @@
1
+ # 为什么需要模块工程解决方案
2
+
3
+ 大家可能都经历过:从零开始开发一个组件库或者工具库的过程中,我们不仅要考虑项目本身的代码逻辑如何编写,还要考虑项目的构建、调试、测试、代码格式化等等和代码逻辑无关的事情。
4
+
5
+ 比如说,当我们考虑构建模块项目的代码是使用什么构建工具的时候,在之前我们可能会考虑使用 [webpack](https://webpack.js.org/) 还是 [Rollup](https://rollupjs.org/guide/en/),然而现在的话,也许还会考虑是使用 [esbuild](https://esbuild.github.io/) 还是 [SWC](https://swc.rs/)。
6
+
7
+ 无论选择哪个构建工具,这对于没有熟练掌握这些构建工具使用方式的开发者来说,是需要一定的成本去学习的。即使想要快速使用,也会需要花费大量的时间和精力。
8
+
9
+ 而除了构建这件事情以外,像为项目提供调试工具、支持测试能力、增加代码格式校验等等,对于一个新手来说都有可能需要花费很长的时间和精力了解或者掌握它们,并且真正的服务于当前的项目中。
10
+
11
+ 而为了保证代码质量以及项目的完整性,我们往往是需要做这些与代码逻辑实现无关的事情。然而这些事情很有可能会影响整体的项目开发进度,降低开发者的开发体验,会让开发者感觉模块项目的开发门槛很高。
12
+
13
+ 如果说每次开发一个模块类型的项目都需要经历一遍这些工作准备的话,那么基本上刚开始开发的时间会大部分花费在这些与代码实现无关的事情上。如果能够提供一个模块工程解决方案,它能够帮助开发者解决项目工程上的事情,让开发者可以更专注于代码的实现上,那么这将会大大提升模块类型项目的开发体验。
14
+
15
+ ![没有使用工程方案对比使用工程方案](/why-module-solution.png)
16
+
17
+ Modern.js 为了让开发模块类型的项目更简单,为了解决上述提到的问题提供了模块工程解决方案,并且使用 Module Tools 提供了主要的功能。**Module-tools 可以理解为是一个专门用于模块类型项目开发的工具**。
@@ -0,0 +1,29 @@
1
+ ---
2
+ pageType: home
3
+
4
+ hero:
5
+ name: Module tools
6
+ text: 模块工程解决方案
7
+ tagline: 简单、强大、高性能的现代化npm包开发方案
8
+ actions:
9
+ - theme: brand
10
+ text: 欢迎使用
11
+ link: /zh/guide/intro/welcome
12
+
13
+ features:
14
+ - title: 'Esbuild: 高性能的JS Bundler'
15
+ details: 基于 Esbuild 构建,构建速度极快,带给你极致的开发体验。
16
+ icon: 🚀
17
+ - title: 'Storybook: 社区流行的UI开发工具'
18
+ details: 集成了Storybook,你可以使用它调试UI。
19
+ icon: 📦
20
+ - title: 'transform + bundle'
21
+ details: 支持bundle和bundleless两种构建模式。
22
+ icon: ✨
23
+ - title: '零配置'
24
+ details: 无需任何配置即可开发你的npm包,内置预设覆盖多种场景。
25
+ icon: 🛠️
26
+ - title: '扩展性强: 提供强大的插件机制'
27
+ details: 通过其插件扩展机制,你可以轻松的扩展Module tools的各项能力。
28
+ icon: 🎨
29
+ ---
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@modern-js/module-tools-docs",
3
+ "version": "2.0.0-beta.4",
4
+ "description": "docs",
5
+ "main": "index.js",
6
+ "keywords": [],
7
+ "author": "",
8
+ "license": "ISC",
9
+ "dependencies": {
10
+ "islandjs": "0.7.19",
11
+ "@code-hike/mdx": "^0.7.4",
12
+ "shiki": "^0.11.1"
13
+ },
14
+ "scripts": {
15
+ "dev": "island dev docs",
16
+ "build": "island build docs",
17
+ "preview": "island start docs"
18
+ }
19
+ }