@modern-js/module-tools-docs 2.46.1 → 2.47.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 +3 -1
- package/docs/en/components/publish-emo.mdx +0 -0
- package/docs/en/guide/basic/{publish-your-project.md → publish-your-project.mdx} +7 -1
- package/docs/en/guide/basic/use-module-doc.mdx +37 -11
- package/docs/en/guide/basic/using-storybook.mdx +3 -5
- package/docs/en/guide/faq/build.mdx +40 -4
- package/docs/en/plugins/official-list/overview.md +1 -1
- package/docs/en/plugins/official-list/plugin-vue.mdx +1 -0
- package/docs/zh/api/config/build-config.mdx +3 -2
- package/docs/zh/components/publish-emo.mdx +0 -0
- package/docs/zh/guide/basic/{publish-your-project.md → publish-your-project.mdx} +7 -1
- package/docs/zh/guide/basic/use-module-doc.mdx +44 -16
- package/docs/zh/guide/basic/using-storybook.mdx +5 -6
- package/docs/zh/guide/faq/build.mdx +36 -0
- package/docs/zh/plugins/official-list/plugin-vue.mdx +1 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
File without changes
|
|
@@ -7,7 +7,13 @@ sidebar_position: 7
|
|
|
7
7
|
An npm-type module project release process consists of two phases.
|
|
8
8
|
|
|
9
9
|
- The first phase is during development, where the developer needs to provide a change file to record changes that need to be released.
|
|
10
|
-
- The second phase is during release,
|
|
10
|
+
- The second phase is during release, collect all the change files to update the version, update the release log, and release new packages to the [npm Registry](https://www.npmjs.com/).
|
|
11
|
+
|
|
12
|
+
Modern.js Module provides a set of version management and release solutions, which are suitable for single-package scenarios. For npm packages in monorepo, you need to follow the strategies provided by various monorepo solutions.
|
|
13
|
+
|
|
14
|
+
import PublishEMO from '@site-docs/components/publish-emo';
|
|
15
|
+
|
|
16
|
+
<PublishEMO />
|
|
11
17
|
|
|
12
18
|
## Tracking changes
|
|
13
19
|
|
|
@@ -56,7 +56,7 @@ The sidebars corresponding in turn to the above file paths and routing paths are
|
|
|
56
56
|
### Configure sidebar
|
|
57
57
|
|
|
58
58
|
As shown in the figure above, the module documentation has automatically generated sidebars for file system routing, where the text of each column of the sidebar is determined by the file's first level title or directory name.
|
|
59
|
-
If you need to customize the sidebar, please use [_meta.json](https://rspress.dev/guide/basic/auto-nav-sidebar.html) or configure [sidebar](https://rspress.dev/api/config/config-theme.html#sidebar) directly.
|
|
59
|
+
If you need to customize the sidebar, please use [\_meta.json](https://rspress.dev/guide/basic/auto-nav-sidebar.html) or configure [sidebar](https://rspress.dev/api/config/config-theme.html#sidebar) directly.
|
|
60
60
|
|
|
61
61
|
:::info
|
|
62
62
|
If your document directory structure complies with internationalization, for example:
|
|
@@ -146,9 +146,9 @@ export default defineConfig({
|
|
|
146
146
|
modulePluginDoc({
|
|
147
147
|
/**
|
|
148
148
|
* Select the preview method
|
|
149
|
-
* @default
|
|
149
|
+
* @default internal
|
|
150
150
|
*/
|
|
151
|
-
previewMode: '
|
|
151
|
+
previewMode: 'iframe',
|
|
152
152
|
/**
|
|
153
153
|
* Select iframe position
|
|
154
154
|
* @default 'follow'
|
|
@@ -167,12 +167,12 @@ If you only want to change the way a particular `jsx` and `tsx` block is preview
|
|
|
167
167
|
// The content here will not be rendered
|
|
168
168
|
```
|
|
169
169
|
|
|
170
|
-
```jsx
|
|
171
|
-
// Used to render
|
|
170
|
+
```jsx internal
|
|
171
|
+
// Used to render components in documentation
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
-
```jsx
|
|
175
|
-
// Used to render
|
|
174
|
+
```jsx iframe
|
|
175
|
+
// Used to render components in iframe
|
|
176
176
|
```
|
|
177
177
|
````
|
|
178
178
|
|
|
@@ -186,6 +186,12 @@ If our demo is very complex, then it is recommended to write the demo separately
|
|
|
186
186
|
<code src="/path/demo.tsx"></code>
|
|
187
187
|
```
|
|
188
188
|
|
|
189
|
+
This also supports setting the preview method for each individual code block, for example:
|
|
190
|
+
|
|
191
|
+
```mdx
|
|
192
|
+
<code src="/path/demo.tsx" previewMode="iframe"></code>
|
|
193
|
+
```
|
|
194
|
+
|
|
189
195
|
## Using built-in components
|
|
190
196
|
|
|
191
197
|
The plugin implements some built-in components internally so that you can develop module documentation more easily.
|
|
@@ -239,7 +245,20 @@ export const Button = (props?: ButtonProps) => {};
|
|
|
239
245
|
```
|
|
240
246
|
|
|
241
247
|
The above is a standard writeup where `ButtonProps` will be extracted into the table and `Button` will be the title of the table.
|
|
242
|
-
If you use the default export, the filename will be used as the form title.
|
|
248
|
+
If you use the default export, the filename will be used as the form title.
|
|
249
|
+
|
|
250
|
+
Notice that export features declared elsewhere are not available.
|
|
251
|
+
|
|
252
|
+
```tsx
|
|
253
|
+
const A = () => {};
|
|
254
|
+
|
|
255
|
+
export { A }; // wrong
|
|
256
|
+
export default A; // wrong
|
|
257
|
+
export const B = () => {}; // right
|
|
258
|
+
export default () => {}; // right
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
The generated content is as follows:
|
|
243
262
|
|
|
244
263
|
```mdx
|
|
245
264
|
### ButtonTest
|
|
@@ -261,6 +280,12 @@ If React types are used in Props, you need to add the types in tsconfig.json, ot
|
|
|
261
280
|
}
|
|
262
281
|
```
|
|
263
282
|
|
|
283
|
+
The best way is that you import the type directly:
|
|
284
|
+
|
|
285
|
+
```tsx
|
|
286
|
+
import { FC } from 'react';
|
|
287
|
+
```
|
|
288
|
+
|
|
264
289
|
:::
|
|
265
290
|
|
|
266
291
|
- `documentation` is used in tool library scenarios to parse JSDoc annotations.
|
|
@@ -398,10 +423,10 @@ type ParseToolOptions = {
|
|
|
398
423
|
|
|
399
424
|
### previewMode
|
|
400
425
|
|
|
401
|
-
- Type:`'
|
|
402
|
-
- Default: `'
|
|
426
|
+
- Type:`'iframe' | 'internal'`
|
|
427
|
+
- Default: `'internal'`
|
|
403
428
|
|
|
404
|
-
In case of `
|
|
429
|
+
In case of `internal`, the component will be rendered directly in the page, otherwise it will be loaded through an iframe.
|
|
405
430
|
|
|
406
431
|
### deprecated: languages
|
|
407
432
|
|
|
@@ -417,6 +442,7 @@ or directly configure [sidebar](https://rspress.dev/api/config/config-theme.html
|
|
|
417
442
|
:::
|
|
418
443
|
|
|
419
444
|
## Scripts
|
|
445
|
+
|
|
420
446
|
- `modern dev`: Start dev server for doc site.
|
|
421
447
|
- `modern build --platform`: Build doc site in production, by default output directories is `doc_build`.
|
|
422
448
|
|
|
@@ -100,8 +100,6 @@ export default config;
|
|
|
100
100
|
|
|
101
101
|
Note that in the above configuration, the reactDocgen configuration has been changed because Rspack currently does not support @storybook/react-docgen-typescript-plugin.
|
|
102
102
|
|
|
103
|
-
Before starting, make sure that you have installed the @modern-js/builder-rspack-provider package.
|
|
104
|
-
|
|
105
103
|
### Configurations
|
|
106
104
|
|
|
107
105
|
There are some separate configurations in `.storybook/main.js`.
|
|
@@ -111,7 +109,7 @@ There are some separate configurations in `.storybook/main.js`.
|
|
|
111
109
|
- **Type**: `'webpack' | 'rspack'`
|
|
112
110
|
- **Default**: `webpack`
|
|
113
111
|
|
|
114
|
-
Specify the underlying
|
|
112
|
+
Specify the underlying bundler to use either Webpack or Rspack.
|
|
115
113
|
|
|
116
114
|
Example:
|
|
117
115
|
|
|
@@ -133,7 +131,7 @@ export default config;
|
|
|
133
131
|
- **Type**: `BuilderConfig`
|
|
134
132
|
- **Default**: `undefined`
|
|
135
133
|
|
|
136
|
-
|
|
134
|
+
The Storybook build capability of Modern.js is provided by [Rsbuild](https://rsbuild.dev/), and the Rsbuild configuration can be modified through builderConfig.
|
|
137
135
|
|
|
138
136
|
```javascript filename='.storybook/main.js'
|
|
139
137
|
const config = {
|
|
@@ -155,7 +153,7 @@ export default config;
|
|
|
155
153
|
|
|
156
154
|
### Command
|
|
157
155
|
|
|
158
|
-
@modern-js/storybook
|
|
156
|
+
@modern-js/storybook proxies some storybook cli commands
|
|
159
157
|
|
|
160
158
|
#### storybook dev
|
|
161
159
|
|
|
@@ -97,6 +97,12 @@ export const libs = {
|
|
|
97
97
|
|
|
98
98
|
In this case `babel-plugin-import` may also cause `Comps` to become `undefined`. So you need to remove the corresponding `babel-plugin-import` as well.
|
|
99
99
|
|
|
100
|
+
### Cannot find module http
|
|
101
|
+
|
|
102
|
+
If the output reports an error like `Cannot find module 'http'` at browser runtime, it means that your output has bundled node modules.
|
|
103
|
+
This may occur if some of your dependencies support both browser and node, such as `axios`, in which case you only need to set the [platform](/api/config/build-config.html/#platform) to `browser`.
|
|
104
|
+
If some third-party packages don't support the browser, you may need to manually inject [node polyfill](/plugins/official-list/plugin-node-polyfill).
|
|
105
|
+
|
|
100
106
|
## Exceptions FAQ
|
|
101
107
|
|
|
102
108
|
import BuildExceptionFAQ from '@site-docs-en/components/faq-build-exception';
|
|
@@ -198,9 +204,9 @@ module.exports = {
|
|
|
198
204
|
return options;
|
|
199
205
|
});
|
|
200
206
|
},
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
204
210
|
},
|
|
205
211
|
};
|
|
206
212
|
```
|
|
@@ -212,7 +218,7 @@ For source code files, it is recommended to fix the type problem, which can bett
|
|
|
212
218
|
|
|
213
219
|
1. enable [skipLibCheck](https://www.typescriptlang.org/tsconfig#skipLibCheck) to skip the d.ts check of the thrid-party package.
|
|
214
220
|
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.
|
|
221
|
+
so you can only turn off [dts.abortOnError](/api/config/build-config.html#dtsabortonerror) to ignore these errors.
|
|
216
222
|
|
|
217
223
|
### Bundle DTS failed
|
|
218
224
|
|
|
@@ -238,6 +244,36 @@ import BuildOtherFAQ from '@site-docs-en/components/faq-build-other';
|
|
|
238
244
|
|
|
239
245
|
<BuildOtherFAQ />
|
|
240
246
|
|
|
247
|
+
### How to skip the pre-processing of less/scss files with bundleless
|
|
248
|
+
|
|
249
|
+
Bundleless is a single-file compilation method. You just need to remove your less/scss files from the entry and copy them to the output.
|
|
250
|
+
Note that we will also rewrite the moduleId of js referencing less/scss, turn it off through the [redirect](/api/config/build-config#redirect) plugin.
|
|
251
|
+
|
|
252
|
+
Below is an example of skipping less file processing. You will find that all less files in src are copied to dist and the relative path is preserved.
|
|
253
|
+
|
|
254
|
+
```ts title="modern.config.ts"
|
|
255
|
+
export default defineConfig({
|
|
256
|
+
buildConfig: {
|
|
257
|
+
buildType: 'bundleless',
|
|
258
|
+
input: ['src', '!src/**/*.less'],
|
|
259
|
+
redirect: {
|
|
260
|
+
style: false,
|
|
261
|
+
},
|
|
262
|
+
copy: {
|
|
263
|
+
patterns: [
|
|
264
|
+
{
|
|
265
|
+
from: './**/*.less',
|
|
266
|
+
to: './',
|
|
267
|
+
},
|
|
268
|
+
],
|
|
269
|
+
options: {
|
|
270
|
+
enableCopySync: true,
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
```
|
|
276
|
+
|
|
241
277
|
### Add additional compilation feature
|
|
242
278
|
|
|
243
279
|
The Modern.js Module is based on the esbuild implementation, so if you have special needs or want to add additional compilation capabilities, you can do so by implementing the esbuild plugin.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Overview
|
|
2
2
|
|
|
3
|
-
## Official
|
|
3
|
+
## Official Plugins
|
|
4
4
|
|
|
5
5
|
* [@modern-js/plugin-module-import](./plugin-import.md):Use SWC to provide the same ability as [`babel-plugin-import`](https://github.com/umijs/babel-plugin-import).
|
|
6
6
|
* [@modern-js/plugin-module-banner](./plugin-banner.md):Add custom content, such as copyright information, to the top and bottom of each JS and CSS file.
|
|
@@ -8,6 +8,7 @@ Notice that we have some limitation:
|
|
|
8
8
|
1. The current implementation of this plugin integrates directly with the community plugin and therefore does not support writing jsx/tsx in sfc.
|
|
9
9
|
2. If you want to generate d.ts for the components, please use the official recommendation [vue-tsc](https://www.npmjs.com/package/vue-tsc).
|
|
10
10
|
3. Only support bundle, we recommend to set input to `['src/**/*.vue']` or `['src/index.ts']`.
|
|
11
|
+
|
|
11
12
|
:::
|
|
12
13
|
|
|
13
14
|
## Quick start
|
|
@@ -485,7 +485,6 @@ export default defineConfig({
|
|
|
485
485
|
});
|
|
486
486
|
```
|
|
487
487
|
|
|
488
|
-
|
|
489
488
|
## dts.only
|
|
490
489
|
|
|
491
490
|
是否在构建时只生成类型文件,不生成 JavaScript 产物文件。
|
|
@@ -1281,7 +1280,9 @@ export default defineConfig({
|
|
|
1281
1280
|
```js title="modern.config.ts"
|
|
1282
1281
|
export default defineConfig({
|
|
1283
1282
|
buildConfig: {
|
|
1284
|
-
|
|
1283
|
+
style: {
|
|
1284
|
+
inject: true,
|
|
1285
|
+
},
|
|
1285
1286
|
},
|
|
1286
1287
|
});
|
|
1287
1288
|
```
|
|
File without changes
|
|
@@ -7,7 +7,13 @@ sidebar_position: 7
|
|
|
7
7
|
一个 npm 类型的模块项目发布流程包含了两个阶段:
|
|
8
8
|
|
|
9
9
|
- 第一阶段是在开发期间,开发者需要提供变更文件,该文件记录了在发布期间需要的变更内容;
|
|
10
|
-
-
|
|
10
|
+
- 第二阶段是在发布期间,需要收集所有的变更文件来更新版本、更新发布日志,并发布新的包到 [npm Registry](https://www.npmjs.com/) 上。
|
|
11
|
+
|
|
12
|
+
Modern.js Module 提供了一套版本管理与发布的方案,这适用于单包场景。对于 monorepo 里的 npm 包你需要遵循各类 monorepo 解决方案提供的策略。
|
|
13
|
+
|
|
14
|
+
import PublishEMO from '@site-docs/components/publish-emo';
|
|
15
|
+
|
|
16
|
+
<PublishEMO />
|
|
11
17
|
|
|
12
18
|
## 跟踪变更
|
|
13
19
|
|
|
@@ -55,10 +55,11 @@ docs
|
|
|
55
55
|
### 配置侧边栏
|
|
56
56
|
|
|
57
57
|
如上图所示,模块文档已经为文件系统路由自动生成了侧边栏,其中侧边栏每一栏的文本是由文件的一级标题或者目录名决定。
|
|
58
|
-
如果你需要自定义侧边栏,请使用 [_meta.json](https://rspress.dev/zh/guide/basic/auto-nav-sidebar.html) 或者直接配置 [sidebar](https://rspress.dev/zh/api/config/config-theme.html#sidebar)。
|
|
58
|
+
如果你需要自定义侧边栏,请使用 [\_meta.json](https://rspress.dev/zh/guide/basic/auto-nav-sidebar.html) 或者直接配置 [sidebar](https://rspress.dev/zh/api/config/config-theme.html#sidebar)。
|
|
59
59
|
|
|
60
60
|
:::info
|
|
61
61
|
如果你的文档目录结构是符合国际化的,例如:
|
|
62
|
+
|
|
62
63
|
```bash
|
|
63
64
|
docs
|
|
64
65
|
├── en
|
|
@@ -68,6 +69,7 @@ docs
|
|
|
68
69
|
├── button.mdx
|
|
69
70
|
├── index.mdx
|
|
70
71
|
```
|
|
72
|
+
|
|
71
73
|
你需要按照[国际化](https://rspress.dev/zh/guide/default-theme/i18n.html)章节,同时配置 `lang` 和 `locales`,否则模块自动生成的侧边栏不会处理 `zh` 和 `en` 这两个目录。
|
|
72
74
|
:::
|
|
73
75
|
|
|
@@ -139,9 +141,9 @@ export default defineConfig({
|
|
|
139
141
|
modulePluginDoc({
|
|
140
142
|
/**
|
|
141
143
|
* 选择预览方式
|
|
142
|
-
* @default
|
|
144
|
+
* @default internal
|
|
143
145
|
*/
|
|
144
|
-
previewMode: '
|
|
146
|
+
previewMode: 'iframe',
|
|
145
147
|
/**
|
|
146
148
|
* 设置 iframe 的位置
|
|
147
149
|
* @default 'follow'
|
|
@@ -160,12 +162,12 @@ export default defineConfig({
|
|
|
160
162
|
// 这里的内容不会被渲染
|
|
161
163
|
```
|
|
162
164
|
|
|
163
|
-
```jsx
|
|
164
|
-
//
|
|
165
|
+
```jsx internal
|
|
166
|
+
// 内置在文档内容里渲染
|
|
165
167
|
```
|
|
166
168
|
|
|
167
|
-
```jsx
|
|
168
|
-
//
|
|
169
|
+
```jsx iframe
|
|
170
|
+
// 使用 iframe 渲染
|
|
169
171
|
```
|
|
170
172
|
````
|
|
171
173
|
|
|
@@ -179,6 +181,12 @@ export default defineConfig({
|
|
|
179
181
|
<code src="/path/demo.tsx"></code>
|
|
180
182
|
```
|
|
181
183
|
|
|
184
|
+
这同样支持单独设置代码块的预览方式,例如:
|
|
185
|
+
|
|
186
|
+
```mdx
|
|
187
|
+
<code src="/path/demo.tsx" previewMode="iframe"></code>
|
|
188
|
+
```
|
|
189
|
+
|
|
182
190
|
## 使用内置组件
|
|
183
191
|
|
|
184
192
|
插件内部实现了一部分内置组件,以便于你可以更轻松地开发模块文档。
|
|
@@ -231,8 +239,20 @@ export type ButtonProps = {
|
|
|
231
239
|
export const Button = (props?: ButtonProps) => {};
|
|
232
240
|
```
|
|
233
241
|
|
|
234
|
-
上面是一个标准写法,其中 `ButtonProps` 将被提取至表格中, `Button`
|
|
235
|
-
|
|
242
|
+
上面是一个标准写法,其中 `ButtonProps` 将被提取至表格中, `Button` 作为表格的标题。如果使用默认导出,文件名将作为表格标题。
|
|
243
|
+
|
|
244
|
+
需要注意的是,export 导出事先定义的特性将不会被解析。
|
|
245
|
+
|
|
246
|
+
```tsx
|
|
247
|
+
const A = () => {};
|
|
248
|
+
|
|
249
|
+
export { A }; // wrong
|
|
250
|
+
export default A; // wrong
|
|
251
|
+
export const B = () => {}; // right
|
|
252
|
+
export default () => {}; // right
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
生成的内容如下:
|
|
236
256
|
|
|
237
257
|
```mdx
|
|
238
258
|
### ButtonTest
|
|
@@ -245,15 +265,22 @@ export const Button = (props?: ButtonProps) => {};
|
|
|
245
265
|
|
|
246
266
|
:::warning
|
|
247
267
|
如果 Props 里使用了 React 的类型,你需要在 tsconfig.json 里添加 types ,否则会解析不到 React 命名空间下的类型。
|
|
268
|
+
|
|
248
269
|
```json
|
|
249
270
|
{
|
|
250
271
|
"compilerOptions": {
|
|
251
|
-
"types": ["react"]
|
|
252
|
-
}
|
|
272
|
+
"types": ["react"]
|
|
273
|
+
}
|
|
253
274
|
}
|
|
254
275
|
```
|
|
255
|
-
:::
|
|
256
276
|
|
|
277
|
+
更好的方式是直接引用类型,例如
|
|
278
|
+
|
|
279
|
+
```tsx
|
|
280
|
+
import { FC } from 'react';
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
:::
|
|
257
284
|
|
|
258
285
|
- `documentation`适用于工具库场景,用来解析 JSDoc 注释。
|
|
259
286
|
|
|
@@ -394,10 +421,10 @@ type ParseToolOptions = {
|
|
|
394
421
|
|
|
395
422
|
代码块预览方式。
|
|
396
423
|
|
|
397
|
-
- 类型:`'
|
|
398
|
-
- 默认值: `'
|
|
424
|
+
- 类型:`'internal' | 'iframe'`
|
|
425
|
+
- 默认值: `'internal'`
|
|
399
426
|
|
|
400
|
-
`
|
|
427
|
+
`internal`时,代码块内容将会直接渲染在页面中,反之将会通过 iframe 加载。
|
|
401
428
|
|
|
402
429
|
### deprecated: languages
|
|
403
430
|
|
|
@@ -408,11 +435,12 @@ type ParseToolOptions = {
|
|
|
408
435
|
### deprecated: useModuleSidebar
|
|
409
436
|
|
|
410
437
|
:::warning
|
|
411
|
-
从 MAJOR_VERSION.44.0 版本开始,内部实现了嗅探机制,请直接使用 [_meta.json](https://rspress.dev/zh/guide/basic/auto-nav-sidebar.html)
|
|
438
|
+
从 MAJOR_VERSION.44.0 版本开始,内部实现了嗅探机制,请直接使用 [\_meta.json](https://rspress.dev/zh/guide/basic/auto-nav-sidebar.html)
|
|
412
439
|
或者直接配置 [sidebar](https://rspress.dev/zh/api/config/config-theme.html#sidebar) 来实现自定义侧边栏。
|
|
413
440
|
:::
|
|
414
441
|
|
|
415
442
|
## 命令行
|
|
443
|
+
|
|
416
444
|
- `modern dev`: 启动文档站本地开发。
|
|
417
445
|
- `modern build --platform`: 构建生产环境产物。
|
|
418
446
|
|
|
@@ -100,7 +100,6 @@ export default config;
|
|
|
100
100
|
```
|
|
101
101
|
|
|
102
102
|
注意上面配置中,更改了 reactDocgen 配置,因为 Rspack 目前还不支持 @storybook/react-docgen-typescript-plugin。
|
|
103
|
-
在启动前,确保已安装 @modern-js/builder-rspack-provider 包。
|
|
104
103
|
|
|
105
104
|
### 配置
|
|
106
105
|
|
|
@@ -111,7 +110,7 @@ export default config;
|
|
|
111
110
|
- **类型**: `'webpack' | 'rspack'`
|
|
112
111
|
- **默认值**: `webpack`
|
|
113
112
|
|
|
114
|
-
|
|
113
|
+
指定底层打包工具使用 Webpack 还是 Rspack。
|
|
115
114
|
|
|
116
115
|
```javascript filename='.storybook/main.js'
|
|
117
116
|
const config = {
|
|
@@ -131,7 +130,7 @@ export default config;
|
|
|
131
130
|
- **类型**: `BuilderConfig`
|
|
132
131
|
- **默认值**: `undefined`
|
|
133
132
|
|
|
134
|
-
|
|
133
|
+
Modern.js 的 Storybook 构建能力由 [Rsbuild](https://rsbuild.dev/) 提供,可通过 builderConfig 修改 Rsbuild 构建配置。
|
|
135
134
|
|
|
136
135
|
```javascript filename='.storybook/main.js'
|
|
137
136
|
const config = {
|
|
@@ -165,14 +164,14 @@ export default config;
|
|
|
165
164
|
|
|
166
165
|
### 配置文件
|
|
167
166
|
|
|
168
|
-
配置文件中除了
|
|
167
|
+
配置文件中除了 Rsbuild 配置还包含一个额外的字段,builderPlugins,方便使用 Rsbuild 插件,例如启用 SWC 编译。
|
|
169
168
|
|
|
170
169
|
```typescript filename='modern.config.ts'
|
|
171
170
|
import { defineConfig } from '@modern-js/storybook';
|
|
172
|
-
import {
|
|
171
|
+
import { pluginSwc } from '@rsbuild/plugin-swc';
|
|
173
172
|
|
|
174
173
|
const config = defineConfig({
|
|
175
|
-
builderPlugins: [
|
|
174
|
+
builderPlugins: [pluginSwc()],
|
|
176
175
|
});
|
|
177
176
|
|
|
178
177
|
export default config;
|
|
@@ -97,6 +97,12 @@ export const libs = {
|
|
|
97
97
|
|
|
98
98
|
此时 `babel-plugin-import` 也可能会导致 `Comps` 变为 `undefined`。因此也需要移除对应的 `babel-plugin-import`。
|
|
99
99
|
|
|
100
|
+
### Cannot find module http
|
|
101
|
+
|
|
102
|
+
如果产物在浏览器运行时报了类似 `Cannot find module 'http'` 的错误,说明你的产物打包进了 node 模块。
|
|
103
|
+
这可能会发生于你的依赖里有一些同时支持 browser 和 node 的三方包,例如 `axios`,此时只需要将 [platform](/api/config/build-config.html/#platform) 设置为 `browser` 即可。
|
|
104
|
+
如果一些三方包不支持 browser, 你可能需要手动注入 [node polyfill](/plugins/official-list/plugin-node-polyfill)。
|
|
105
|
+
|
|
100
106
|
## 异常类问题
|
|
101
107
|
|
|
102
108
|
import BuildExceptionFAQ from '@site-docs/components/faq-build-exception';
|
|
@@ -235,6 +241,36 @@ import BuildOtherFAQ from '@site-docs/components/faq-build-other';
|
|
|
235
241
|
|
|
236
242
|
<BuildOtherFAQ />
|
|
237
243
|
|
|
244
|
+
### bundleless 如何跳过对 less / scss 文件的预处理
|
|
245
|
+
|
|
246
|
+
bundleless 是单文件编译的方式,只需要将你的 less / scss 文件从入口里移除并且将其拷贝到产物里即可。
|
|
247
|
+
注意我们还会把 js 引用 less / scss 的 moduleId 进行改写,你可以通过 [redirect](/api/config/build-config#redirect) 配置关闭它。
|
|
248
|
+
|
|
249
|
+
下面是一个跳过 less 文件处理的例子,你会发现 src 里面所有的 less 文件都被拷贝到 dist 里并且保留了一致的相对路径。
|
|
250
|
+
|
|
251
|
+
```ts title="modern.config.ts"
|
|
252
|
+
export default defineConfig({
|
|
253
|
+
buildType: 'bundleless',
|
|
254
|
+
buildConfig: {
|
|
255
|
+
input: ['src', '!src/**/*.less'],
|
|
256
|
+
redirect: {
|
|
257
|
+
style: false,
|
|
258
|
+
},
|
|
259
|
+
copy: {
|
|
260
|
+
patterns: [
|
|
261
|
+
{
|
|
262
|
+
from: './**/*.less',
|
|
263
|
+
to: './',
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
options: {
|
|
267
|
+
enableCopySync: true,
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
```
|
|
273
|
+
|
|
238
274
|
### 增加额外的编译能力
|
|
239
275
|
|
|
240
276
|
Modern.js Module 基于 esbuild 实现,因此如果有特殊需求或者想要增加额外的编译能力,可以通过实现 esbuild 插件来解决。
|
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.47.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.12.3",
|
|
18
|
+
"@rspress/shared": "1.12.3",
|
|
19
|
+
"@modern-js/doc-plugin-auto-sidebar": "2.47.1"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"dev": "rspress dev",
|