@modern-js/module-tools-docs 2.25.1 → 2.25.2

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 (40) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/docs/en/api/config/build-config.md +9 -9
  3. package/docs/en/api/config/build-preset.mdx +4 -4
  4. package/docs/en/components/faq-build-exception.mdx +1 -0
  5. package/docs/en/components/faq-build-other.mdx +0 -0
  6. package/docs/en/components/faq-build-product.mdx +0 -0
  7. package/docs/en/components/faq-storybook.mdx +0 -0
  8. package/docs/en/components/faq-test.mdx +1 -0
  9. package/docs/en/guide/advance/asset.mdx +2 -2
  10. package/docs/en/guide/advance/build-umd.mdx +9 -9
  11. package/docs/en/guide/advance/copy.md +1 -1
  12. package/docs/en/guide/advance/external-dependency.mdx +2 -2
  13. package/docs/en/guide/advance/in-depth-about-build.md +11 -11
  14. package/docs/en/guide/advance/in-depth-about-dev-command.md +1 -1
  15. package/docs/en/guide/basic/before-getting-started.md +1 -1
  16. package/docs/en/guide/basic/command-preview.md +5 -5
  17. package/docs/en/guide/basic/modify-output-product.md +18 -18
  18. package/docs/en/guide/basic/using-storybook.mdx +1 -1
  19. package/docs/en/guide/best-practices/components.mdx +10 -10
  20. package/docs/en/guide/faq/_category_.json +4 -0
  21. package/docs/en/guide/faq/build.mdx +247 -0
  22. package/docs/en/guide/faq/index.md +7 -0
  23. package/docs/en/guide/faq/storybook.mdx +102 -0
  24. package/docs/en/guide/faq/test.mdx +11 -0
  25. package/docs/en/guide/intro/welcome.md +2 -2
  26. package/docs/en/plugins/guide/getting-started.mdx +1 -1
  27. package/docs/en/plugins/guide/plugin-object.mdx +2 -2
  28. package/docs/en/plugins/guide/setup-function.mdx +1 -1
  29. package/docs/zh/components/faq-build-exception.mdx +1 -0
  30. package/docs/zh/components/faq-build-other.mdx +0 -0
  31. package/docs/zh/components/faq-build-product.mdx +0 -0
  32. package/docs/zh/components/faq-storybook.mdx +0 -0
  33. package/docs/zh/components/faq-test.mdx +1 -0
  34. package/docs/zh/guide/faq/_category_.json +4 -0
  35. package/docs/zh/guide/faq/build.mdx +247 -0
  36. package/docs/zh/guide/faq/index.md +7 -0
  37. package/docs/zh/guide/faq/storybook.mdx +101 -0
  38. package/docs/zh/guide/faq/test.mdx +11 -0
  39. package/modern.config.ts +7 -0
  40. package/package.json +3 -3
@@ -0,0 +1,7 @@
1
+ # 常见问题
2
+
3
+ 这里是 Modern.js Module 常见问题分类列表:
4
+
5
+ - [代码构建相关的问题](./build.mdx)
6
+ - [测试相关的问题](./test.mdx)
7
+ - [Storybook 相关的问题](./storybook.mdx)
@@ -0,0 +1,101 @@
1
+ # Storybook 相关问题
2
+
3
+ import BuildStorybookFAQ from '@site-docs/components/faq-storybook';
4
+
5
+ <BuildStorybookFAQ />
6
+
7
+ ## 支持 Storybook v7
8
+
9
+ Storybook v7 目前还没支持,目前计划在 Storybook v7 中支持 Rspack 构建,因此进度会慢一些。
10
+ 相关 Issue:[#3376](https://github.com/web-infra-dev/modern.js/issues/3376)。
11
+
12
+ ## 使用 Storybook Addon 或者其他配置不生效
13
+
14
+ Modern.js Module 目前使用的 Storybook 版本是 v6,如果使用了 v7 版本的 Addon 可能会出现插件不生效的情况。
15
+
16
+ 除了 Addon 以外,其他配置也可能会有区别。比如修改 `preview.js` 配置文件的话,Storybook v6 与 v7 的写法也不相同:
17
+
18
+ - v6:[文档链接](https://storybook.js.org/docs/6.5/react/writing-stories/decorators#global-decorators)
19
+ - v7:[文档链接](https://storybook.js.org/docs/react/writing-stories/decorators#global-decorators)
20
+
21
+ ## Cannot find module 'react-dom/package.json
22
+
23
+ 在执行 Storybook 调试的时候,出现下面的报错提示:
24
+
25
+ ```bash
26
+ ERR! Error: Cannot find module 'react-dom/package.json'
27
+ ```
28
+
29
+ 解决办法:在项目中安装 `react-dom` 依赖。
30
+
31
+ ``` json
32
+ {
33
+ "devDependencies": {
34
+ "react-dom": "^17"
35
+ }
36
+ }
37
+ ```
38
+
39
+ ## 报错后,看不到具体报错信息
40
+
41
+ 解决办法:
42
+
43
+ 1. 找到 `@storybook/core-server/dist/cjs/dev-server.js`
44
+ 2. 找到 `var _await$Promise$all = await Promise.all([preview, manager` 这附近的代码。
45
+ 3. 修改成:
46
+
47
+ ``` js
48
+ var _await$Promise$all = await Promise.all([
49
+ preview.catch(e => console.info(e)),
50
+ manager // TODO #13083 Restore this when compiling the preview is fast enough
51
+ // .then((result) => {
52
+ // if (!options.ci && !options.smokeTest) openInBrowser(address);
53
+ // return result;
54
+ // })
55
+ .catch(previewBuilder.bail)]),
56
+ _await$Promise$all2 = _slicedToArray(_await$Promise$all, 2),
57
+ previewResult = _await$Promise$all2[0],
58
+ managerResult = _await$Promise$all2[1]; // TODO #13083 Remove this when compiling the preview is fast enough
59
+ ```
60
+
61
+ ## Couldn't find any stories is your Storybook
62
+
63
+ ![storybook-error](https://lf3-static.bytednsdoc.com/obj/eden-cn/shylnyhaeh7uldvivhn/screenshot-20230703-162111.png)
64
+
65
+ 当在预览区域看到类似这样的报错提示的时候,首先可以打开一下浏览器的控制台,应该会有些报错信息。可以先根据报错信息来推断是不是编写代码里出现的问题导致 Storybook 无法正常运行。修复后,再次刷新查看是否正常。
66
+
67
+ ## Storybook 添加 Proxy 功能
68
+
69
+ Storybook 没有提供相关方案,不过 Storybook Issue 中有找到相关的解决办法。在 Modern.js Module 中,你可以:
70
+
71
+ 1. 添加 `config/storybook/middleware.js` 文件,并初始化下面的内容:
72
+
73
+ ``` js
74
+ /* eslint-disable filenames/match-exported */
75
+ module.exports = function expressMiddleware(router) {
76
+ // router is express router
77
+ // import { Router } from 'express'
78
+ // router = new Router();
79
+ };
80
+ ```
81
+
82
+ 2. 添加 http-proxy-middleware 依赖
83
+ 3. 添加代理路由相关配置
84
+
85
+ ``` js
86
+ /* eslint-disable filenames/match-exported */
87
+ const { createProxyMiddleware } = require("http-proxy-middleware");
88
+
89
+ module.exports = function expressMiddleware (router) {
90
+ router.use('/api', createProxyMiddleware({
91
+ target: "http://localhost:8000",
92
+ changeOrigin: true
93
+ }))
94
+ }
95
+ ```
96
+
97
+ 相关 issue 链接:[#11551](https://github.com/storybookjs/storybook/issues/11551)。
98
+
99
+ ## 修改存在 Story 文件的目录
100
+
101
+ 目前暂时无法修改存放 Story 文件的目录,仅对 `your-project/stories` 目录下的 `*.stories.(t|j)s(x)`、`*.stories.md(x)` 文件识别为 Story 文件。
@@ -0,0 +1,11 @@
1
+ # 测试相关问题
2
+
3
+ import TestFAQ from '@site-docs/components/faq-test';
4
+
5
+ <TestFAQ />
6
+
7
+ ## 执行 `test` 命令报错 `TypeError: Cannot read property 'testEnvironmentOptions' of undefined`
8
+
9
+ ![jest-error](https://lf3-static.bytednsdoc.com/obj/eden-cn/shylnyhaeh7uldvivhn/jest-error-testEnvironmentOptions-of-undefined.jpeg)
10
+
11
+ 问题原因多是存在多个版本的 `jest-environment-jsdom` 依赖,可以检查 Monorepo 中其他项目是否有 `jest-environment-jsdom` 依赖,并通过 Monorepo 提供的 overrides 能力统一依赖版本。
package/modern.config.ts CHANGED
@@ -123,6 +123,13 @@ export default defineConfig({
123
123
  dev: {
124
124
  startUrl: 'http://localhost:<port>/module-tools/',
125
125
  },
126
+ source: {
127
+ alias: {
128
+ '@site-docs': path.join(__dirname, './docs/zh'),
129
+ '@site-docs-en': path.join(__dirname, './docs/en'),
130
+ '@site': require('path').resolve(__dirname),
131
+ },
132
+ }
126
133
  },
127
134
  },
128
135
  });
package/package.json CHANGED
@@ -9,15 +9,15 @@
9
9
  "directory": "packages/document/module-doc"
10
10
  },
11
11
  "license": "MIT",
12
- "version": "2.25.1",
12
+ "version": "2.25.2",
13
13
  "main": "index.js",
14
14
  "dependencies": {
15
15
  "@code-hike/mdx": "^0.7.4",
16
16
  "react": "^18.2.0",
17
17
  "react-dom": "^18.2.0",
18
18
  "shiki": "^0.11.1",
19
- "@modern-js/doc-plugin-auto-sidebar": "2.25.1",
20
- "@modern-js/doc-tools": "2.25.1"
19
+ "@modern-js/doc-tools": "2.25.2",
20
+ "@modern-js/doc-plugin-auto-sidebar": "2.25.2"
21
21
  },
22
22
  "scripts": {
23
23
  "dev": "modern dev",