@modern-js/module-tools-docs 2.32.1 → 2.33.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.
- package/.eslintrc.js +1 -1
- package/CHANGELOG.md +11 -0
- package/docs/en/api/config/build-config.mdx +17 -16
- package/docs/en/api/config/build-preset.mdx +11 -72
- package/docs/en/guide/advance/asset.mdx +1 -1
- package/docs/en/guide/advance/copy.md +17 -18
- package/docs/en/guide/advance/external-dependency.mdx +1 -1
- package/docs/en/guide/advance/in-depth-about-build.md +27 -28
- package/docs/en/guide/advance/in-depth-about-dev-command.md +1 -1
- package/docs/en/guide/basic/before-getting-started.md +1 -1
- package/docs/en/guide/basic/modify-output-product.md +44 -70
- package/docs/en/guide/basic/test-your-project.mdx +0 -2
- package/docs/en/guide/basic/use-micro-generator.md +12 -37
- package/docs/en/guide/basic/using-storybook.mdx +15 -0
- package/docs/en/guide/best-practices/components.mdx +5 -198
- package/docs/en/guide/best-practices/use-tailwindcss.mdx +289 -0
- package/docs/en/plugins/guide/setup-function.mdx +0 -1
- package/docs/zh/api/config/build-config.mdx +19 -20
- package/docs/zh/api/config/build-preset.mdx +12 -69
- package/docs/zh/guide/advance/asset.mdx +3 -6
- package/docs/zh/guide/advance/copy.md +0 -2
- package/docs/zh/guide/advance/external-dependency.mdx +1 -1
- package/docs/zh/guide/advance/in-depth-about-build.md +30 -56
- package/docs/zh/guide/basic/before-getting-started.md +1 -1
- package/docs/zh/guide/basic/modify-output-product.md +46 -69
- package/docs/zh/guide/basic/use-micro-generator.md +13 -33
- package/docs/zh/guide/basic/using-storybook.mdx +16 -5
- package/docs/zh/guide/best-practices/components.mdx +1 -196
- package/docs/zh/guide/best-practices/use-tailwindcss.mdx +289 -0
- package/docs/zh/plugins/guide/setup-function.mdx +0 -1
- package/package.json +7 -6
- package/rspress.config.ts +130 -0
- package/theme/index.ts +3 -2
- package/tsconfig.json +1 -1
- package/docs/en/api/config/design-system.md +0 -1166
- package/docs/en/guide/advance/theme-config.mdx +0 -60
- package/docs/zh/api/config/design-system.md +0 -1166
- package/docs/zh/guide/advance/theme-config.mdx +0 -64
- package/modern.config.ts +0 -124
package/.eslintrc.js
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @modern-js/module-tools-docs
|
|
2
2
|
|
|
3
|
+
## 2.33.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- bc1f8da: feat(builder): support custom logger in dev server
|
|
8
|
+
|
|
9
|
+
feat(builder): 支持自定义 logger
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [db9a700]
|
|
12
|
+
- @modern-js/doc-plugin-auto-sidebar@2.33.0
|
|
13
|
+
|
|
3
14
|
## 2.32.1
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -7,7 +7,6 @@ sidebar_position: 1
|
|
|
7
7
|
`buildConfig` is a configuration option that describes how to compile and generate build artifacts. It contains all the configurations related to the build process.
|
|
8
8
|
|
|
9
9
|
- **Type**: `object | object[]`
|
|
10
|
-
- **Default**: `undefined`
|
|
11
10
|
|
|
12
11
|
:::tip
|
|
13
12
|
Before start using `buildConfig`, please read the following documentation to understand its purpose:
|
|
@@ -523,7 +522,7 @@ Used to set the output format of JavaScript files. The options `iife` and `umd`
|
|
|
523
522
|
- **Type**: `'esm' | 'cjs' | 'iife' | 'umd'`
|
|
524
523
|
- **Default**: `cjs`
|
|
525
524
|
|
|
526
|
-
### format:
|
|
525
|
+
### format: esm
|
|
527
526
|
|
|
528
527
|
`esm` stands for "ECMAScript module" and requires the runtime environment to support import and export syntax.
|
|
529
528
|
|
|
@@ -537,7 +536,7 @@ export default defineConfig({
|
|
|
537
536
|
});
|
|
538
537
|
```
|
|
539
538
|
|
|
540
|
-
### format:
|
|
539
|
+
### format: cjs
|
|
541
540
|
|
|
542
541
|
`cjs` stands for "CommonJS" and requires the runtime environment to support exports, require, and module syntax. This format is commonly used in Node.js environments.
|
|
543
542
|
|
|
@@ -551,7 +550,7 @@ export default defineConfig({
|
|
|
551
550
|
});
|
|
552
551
|
```
|
|
553
552
|
|
|
554
|
-
### format:
|
|
553
|
+
### format: iife
|
|
555
554
|
|
|
556
555
|
`iife` stands for "immediately-invoked function expression" and wraps the code in a function expression to ensure that any variables in the code do not accidentally conflict with variables in the global scope. This format is commonly used in browser environments.
|
|
557
556
|
|
|
@@ -1086,13 +1085,10 @@ For detailed configuration see [postcss-modules](https://github.com/madyankin/po
|
|
|
1086
1085
|
|
|
1087
1086
|
## style.tailwindcss
|
|
1088
1087
|
|
|
1089
|
-
|
|
1088
|
+
Used to modify the configuration of [Tailwind CSS](https://tailwindcss.com/docs/configuration).
|
|
1090
1089
|
|
|
1091
1090
|
- **Type**: `object | Function`
|
|
1092
|
-
- **Default**:
|
|
1093
|
-
|
|
1094
|
-
<details>
|
|
1095
|
-
<summary>Tailwind CSS configuration details</summary>
|
|
1091
|
+
- **Default**:
|
|
1096
1092
|
|
|
1097
1093
|
```js title="modern.config.ts"
|
|
1098
1094
|
const tailwind = {
|
|
@@ -1104,7 +1100,13 @@ const tailwind = {
|
|
|
1104
1100
|
};
|
|
1105
1101
|
```
|
|
1106
1102
|
|
|
1107
|
-
|
|
1103
|
+
### Enabling Tailwind CSS
|
|
1104
|
+
|
|
1105
|
+
Before using `style.tailwindcss`, you need to enable the Tailwind CSS plugin for Module Tools.
|
|
1106
|
+
|
|
1107
|
+
Please refer to the section [Using Tailwind CSS](/guide/best-practices/use-tailwindcss.html) for instructions on how to enable it.
|
|
1108
|
+
|
|
1109
|
+
### Type
|
|
1108
1110
|
|
|
1109
1111
|
When the value is of type `object`, it is merged with the default configuration via `Object.assign`.
|
|
1110
1112
|
|
|
@@ -1114,7 +1116,10 @@ The rest of the usage is the same as Tailwind CSS: [Quick Portal](https://tailwi
|
|
|
1114
1116
|
|
|
1115
1117
|
### Notes
|
|
1116
1118
|
|
|
1117
|
-
Please note that
|
|
1119
|
+
Please note that:
|
|
1120
|
+
|
|
1121
|
+
- If you are using both the `tailwind.config.{ts,js}` file and `tools.tailwindcss` option, the configuration defined in `tools.tailwindcss` will take precedence and override the content defined in `tailwind.config.{ts,js}`.
|
|
1122
|
+
- If you are using the `designSystem` configuration option simultaneously, the `theme` configuration of Tailwind CSS will be overridden by the value of `designSystem`.
|
|
1118
1123
|
|
|
1119
1124
|
The usage of other configurations follows the same approach as the official usage of Tailwind CSS. Please refer to [tailwindcss - Configuration](https://tailwindcss.com/docs/configuration) for more details.
|
|
1120
1125
|
|
|
@@ -1176,8 +1181,6 @@ export default defineConfig({
|
|
|
1176
1181
|
});
|
|
1177
1182
|
```
|
|
1178
1183
|
|
|
1179
|
-
### Notes
|
|
1180
|
-
|
|
1181
1184
|
Reference the [Import Plugin - Notes](plugins/official-list/plugin-import.html#Notes)
|
|
1182
1185
|
|
|
1183
1186
|
## transformLodash
|
|
@@ -1189,8 +1192,6 @@ This optimization is implemented using [babel-plugin-lodash](https://www.npmjs.c
|
|
|
1189
1192
|
- **Type**: `boolean`
|
|
1190
1193
|
- **Default**: `true`
|
|
1191
1194
|
|
|
1192
|
-
### Example
|
|
1193
|
-
|
|
1194
1195
|
This option is enabled by default, and Module Tools will automatically redirects the code references of `lodash` to sub-paths.
|
|
1195
1196
|
|
|
1196
1197
|
For example:
|
|
@@ -1267,7 +1268,7 @@ At this point the umd artifact will go to mount on `global.myLib`
|
|
|
1267
1268
|
|
|
1268
1269
|
- The module name of the umd artifact must not conflict with the global variable name.
|
|
1269
1270
|
- Module names will be converted to camelCase, e.g. `my-lib` will be converted to `myLib`, refer to [toIdentifier](https://github.com/babel/babel/blob/main/packages/babel-types/src/converters/toIdentifier.ts).
|
|
1270
|
-
:::
|
|
1271
|
+
:::
|
|
1271
1272
|
|
|
1272
1273
|
Also the function form can take one parameter, which is the output path of the current package file
|
|
1273
1274
|
|
|
@@ -7,21 +7,8 @@ sidebar_position: 2
|
|
|
7
7
|
A build preset string or preset function. Provides out-of-the-box build configuration
|
|
8
8
|
|
|
9
9
|
- **Type**: `string | Function`
|
|
10
|
-
- **Default**: `undefined`
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
The string form allows you to use the built-in presets directly
|
|
15
|
-
|
|
16
|
-
```js title="modern.config.ts"
|
|
17
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
18
|
-
|
|
19
|
-
export default defineConfig({
|
|
20
|
-
buildPreset: 'npm-library',
|
|
21
|
-
});
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
### `'npm-library'`
|
|
11
|
+
### `npm-library`
|
|
25
12
|
|
|
26
13
|
Library generic schema used under class [NPM](https://www.npmjs.com/) package manager, contains `esm` and `cjs` Bundle products, and includes a type file.
|
|
27
14
|
|
|
@@ -68,7 +55,7 @@ export const buildConfig = [
|
|
|
68
55
|
];
|
|
69
56
|
```
|
|
70
57
|
|
|
71
|
-
### `
|
|
58
|
+
### `npm-library-with-umd`
|
|
72
59
|
|
|
73
60
|
Used under class [NPM](https://www.npmjs.com/) package manager, and Library supports a similar pattern to [unpkg](https://unpkg.com/). Additional `umd` artifacts are provided on top of the pre-defined `npm-library`.
|
|
74
61
|
|
|
@@ -114,7 +101,7 @@ export const buildConfig = [
|
|
|
114
101
|
];
|
|
115
102
|
```
|
|
116
103
|
|
|
117
|
-
### `
|
|
104
|
+
### `npm-component`
|
|
118
105
|
|
|
119
106
|
A generic pattern for components (libraries) used under the class [NPM](https://www.npmjs.com/) package manager. Contains both `esm` and `cjs` Bundleless artifacts (for easy _[Tree shaking](https://developer.mozilla.org/zh-CN/docs/Glossary/Tree_shaking)_ optimization), as well as including a copy of the type file.
|
|
120
107
|
|
|
@@ -154,7 +141,7 @@ export const buildConfig = [
|
|
|
154
141
|
];
|
|
155
142
|
```
|
|
156
143
|
|
|
157
|
-
### `
|
|
144
|
+
### `npm-component-with-umd`
|
|
158
145
|
|
|
159
146
|
Component (library) used under class [NPM](https://www.npmjs.com/) package manager, with support for class [unpkg](https://unpkg.com/) schema. Additional `umd` artifacts are provided on top of the pre-defined `npm-component`.
|
|
160
147
|
|
|
@@ -198,7 +185,7 @@ export const buildConfig = [
|
|
|
198
185
|
];
|
|
199
186
|
```
|
|
200
187
|
|
|
201
|
-
###
|
|
188
|
+
### `npm-library-{es5...esnext}`
|
|
202
189
|
|
|
203
190
|
When you want to use a `buildPreset` preset that supports other ECMAScript versions, you can directly add the supported versions to the `'npm-library'`, `'npm-library-with-umd'`, `'npm-component'`, `'npm-component-with-umd'` presets.
|
|
204
191
|
|
|
@@ -212,11 +199,11 @@ export default defineConfig({
|
|
|
212
199
|
});
|
|
213
200
|
```
|
|
214
201
|
|
|
215
|
-
## Function
|
|
202
|
+
## string / Function
|
|
216
203
|
|
|
217
|
-
The
|
|
204
|
+
The buildPreset not only supports basic string forms, but also function forms, which can obtain the default values we provide through the preset or extend Preset parameter and then modify them.
|
|
218
205
|
|
|
219
|
-
|
|
206
|
+
Here are two examples using preset and extend Preset:
|
|
220
207
|
|
|
221
208
|
```js title="modern.config.ts"
|
|
222
209
|
import { defineConfig } from '@modern-js/module-tools';
|
|
@@ -225,63 +212,15 @@ export default defineConfig({
|
|
|
225
212
|
buildPreset({ preset }) {
|
|
226
213
|
const { NPM_LIBRARY } = preset;
|
|
227
214
|
return NPM_LIBRARY.map(config => {
|
|
228
|
-
config.
|
|
229
|
-
|
|
230
|
-
drop_console: true,
|
|
231
|
-
},
|
|
215
|
+
config.define = {
|
|
216
|
+
VERSION: '1.0.1',
|
|
232
217
|
};
|
|
233
218
|
return config;
|
|
234
219
|
});
|
|
235
220
|
},
|
|
236
221
|
});
|
|
237
222
|
```
|
|
238
|
-
|
|
239
|
-
### Function Parameters
|
|
240
|
-
|
|
241
|
-
The function form of `buildPreset` contains a function parameter in the form of an object. The object contains the following fields.
|
|
242
|
-
|
|
243
|
-
- `preset`
|
|
244
|
-
- `extendPreset`
|
|
245
|
-
|
|
246
|
-
#### `preset`
|
|
247
|
-
|
|
248
|
-
Type: **Object**
|
|
249
|
-
|
|
250
|
-
Contains the build configurations corresponding to all available build presets. Build configurations can be used by means of the strings supported by `buildPreset` or by means of underscore commands for those strings. The following are examples of the use of both approaches.
|
|
251
|
-
|
|
252
|
-
- Use the strings supported by `buildPreset`.
|
|
253
|
-
|
|
254
|
-
```ts title="modern.config.ts"
|
|
255
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
256
|
-
|
|
257
|
-
export default defineConfig({
|
|
258
|
-
buildPreset({ preset }) {
|
|
259
|
-
return preset['npm-library'];
|
|
260
|
-
},
|
|
261
|
-
});
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
- Use the underscore naming convention for strings supported by `buildPreset`.
|
|
265
|
-
|
|
266
|
-
```ts title="modern.config.ts"
|
|
267
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
268
|
-
|
|
269
|
-
export default defineConfig({
|
|
270
|
-
buildPreset({ preset }) {
|
|
271
|
-
return preset.NPM_LIBRARY;
|
|
272
|
-
},
|
|
273
|
-
});
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
#### `extendPreset`
|
|
277
|
-
|
|
278
|
-
Type: `Function`
|
|
279
|
-
|
|
280
|
-
Tool function for extending a `buildPreset` to modify the build configuration corresponding to the `buildPreset`.
|
|
281
|
-
|
|
282
|
-
> The base uses something like `{...oldBuildConfig, ...extendBuildConfig}` approach to processing.
|
|
283
|
-
|
|
284
|
-
For example, adding the `define` configuration to the `'npm-library'` build preset.
|
|
223
|
+
In the `extend Preset`, lodash.merge is used for configuration merge.
|
|
285
224
|
|
|
286
225
|
```ts title="modern.config.ts"
|
|
287
226
|
import { defineConfig } from '@modern-js/module-tools';
|
|
@@ -19,7 +19,7 @@ For the handling of static files, the module project currently supports the foll
|
|
|
19
19
|
- Set the static resource path to `. /assets`.
|
|
20
20
|
- Files less than **10kb** will be inlined into the code.
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
## Example
|
|
23
23
|
|
|
24
24
|
Let us look at the following example:
|
|
25
25
|
|
|
@@ -13,13 +13,11 @@ We can use the Copy tool via the [`buildConfig.copy`](/en/api/config/build-confi
|
|
|
13
13
|
- [`patterns`](/en/api/config/build-config#copypatterns)
|
|
14
14
|
- [`options`](/en/api/config/build-config#copyoptions)
|
|
15
15
|
|
|
16
|
-
It is recommended to spend some time getting to know them before you start learning.
|
|
17
|
-
|
|
18
16
|
## API Description
|
|
19
17
|
|
|
20
|
-
`copy.patterns`
|
|
18
|
+
`copy.patterns` is used to find files to be copied and configure the output path.
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
The `patterns.from` parameter is used to specify the file or directory to be copied. It accepts either a Glob pattern string or a specific path. A Glob pattern string refers to the [fast-glob pattern syntax](https://github.com/mrmlnc/fast-glob#pattern-syntax). Therefore, we can use it in two ways as follows:
|
|
23
21
|
|
|
24
22
|
```ts
|
|
25
23
|
export default defineConfig({
|
|
@@ -34,9 +32,10 @@ export default defineConfig({
|
|
|
34
32
|
});
|
|
35
33
|
```
|
|
36
34
|
|
|
37
|
-
`patterns.context` 一般和 `patterns.from` 配合使用,默认情况下它的值与 [`buildConfig.sourceDir`](/api/config/build-config#sourcedir) 相同,因此我们可以按照如下方式指定 `src/data.json` 文件为要复制的文件:
|
|
38
35
|
|
|
39
|
-
|
|
36
|
+
The `patterns.context` parameter is generally used in conjunction with `patterns.from`. By default, its value is the same as [`buildConfig.sourceDir`](/api/config/build-config#sourcedir). Therefore, we can specify the file `src/data.json` to be copied in the following way:
|
|
37
|
+
|
|
38
|
+
> By default, `buildConfig.sourceDir` is set to `src`.
|
|
40
39
|
|
|
41
40
|
```ts
|
|
42
41
|
export default defineConfig({
|
|
@@ -50,7 +49,7 @@ export default defineConfig({
|
|
|
50
49
|
});
|
|
51
50
|
```
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
When the specified file is not in the source code directory, you can modify the `context` configuration. For example, to specify the file `temp/index.html` in the project directory to be copied:
|
|
54
53
|
|
|
55
54
|
```ts
|
|
56
55
|
import path from 'path';
|
|
@@ -70,7 +69,7 @@ export default defineConfig({
|
|
|
70
69
|
});
|
|
71
70
|
```
|
|
72
71
|
|
|
73
|
-
`patterns.to`
|
|
72
|
+
The `patterns.to` parameter is used to specify the output path for the copied files. By default, its value corresponds to [buildConfig.outDir](/api/config/build-config#outDir). Therefore, we can copy `src/index.html` to the `dist` directory as follows:
|
|
74
73
|
|
|
75
74
|
```ts
|
|
76
75
|
export default defineConfig({
|
|
@@ -82,18 +81,18 @@ export default defineConfig({
|
|
|
82
81
|
});
|
|
83
82
|
```
|
|
84
83
|
|
|
85
|
-
|
|
84
|
+
When we configure `patterns.to`:
|
|
86
85
|
|
|
87
|
-
-
|
|
88
|
-
-
|
|
86
|
+
- If it is a relative path, the path will be calculated relative to `buildConfig.outDir` to determine the absolute path for copying the files.
|
|
87
|
+
- If it is an absolute path, the value will be used directly.
|
|
89
88
|
|
|
90
|
-
|
|
89
|
+
Finally, `patterns.globOptions` is used to configure the [globby](https://github.com/sindresorhus/globby) object for finding files to copy. Its configuration can be referenced from:
|
|
91
90
|
|
|
92
91
|
- [globby.options](https://github.com/sindresorhus/globby#options)
|
|
93
92
|
|
|
94
|
-
##
|
|
93
|
+
## Examples of Different Scenarios
|
|
95
94
|
|
|
96
|
-
###
|
|
95
|
+
### Copying Files
|
|
97
96
|
|
|
98
97
|
```ts
|
|
99
98
|
export default defineConfig({
|
|
@@ -117,7 +116,7 @@ export default defineConfig({
|
|
|
117
116
|
});
|
|
118
117
|
```
|
|
119
118
|
|
|
120
|
-
###
|
|
119
|
+
### Copying Files to a Directory
|
|
121
120
|
|
|
122
121
|
```ts
|
|
123
122
|
export default defineConfig({
|
|
@@ -141,7 +140,7 @@ export default defineConfig({
|
|
|
141
140
|
});
|
|
142
141
|
```
|
|
143
142
|
|
|
144
|
-
###
|
|
143
|
+
### Copying from Directory to Directory
|
|
145
144
|
|
|
146
145
|
```ts
|
|
147
146
|
export default defineConfig({
|
|
@@ -168,7 +167,7 @@ export default defineConfig({
|
|
|
168
167
|
});
|
|
169
168
|
```
|
|
170
169
|
|
|
171
|
-
###
|
|
170
|
+
### Copying from Directory to File
|
|
172
171
|
|
|
173
172
|
```ts
|
|
174
173
|
export default defineConfig({
|
|
@@ -195,7 +194,7 @@ export default defineConfig({
|
|
|
195
194
|
});
|
|
196
195
|
```
|
|
197
196
|
|
|
198
|
-
###
|
|
197
|
+
### Using Glob
|
|
199
198
|
|
|
200
199
|
```ts
|
|
201
200
|
export default defineConfig({
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
sidebar_position: 4
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# Handle third-party dependencies
|
|
6
6
|
|
|
7
7
|
Generally, third-party dependencies required by a project can be installed via the `install` command in the package manager. After the third-party dependencies are successfully installed, they will generally appear under `dependencies` and `devDependencies` in the project `package.json`.
|
|
8
8
|
|
|
@@ -12,43 +12,43 @@ If you are not familiar with `buildConfig`, please read [modify-output-product](
|
|
|
12
12
|
|
|
13
13
|
In this chapter we'll dive into the use of certain build configurations and understand what happens when the `modern build` command is executed.
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## buildConfig
|
|
16
16
|
|
|
17
|
-
###
|
|
17
|
+
### `bundle` / `bundleless`
|
|
18
18
|
|
|
19
|
-
So first let's understand
|
|
19
|
+
So first let's understand bundle and bundleless.
|
|
20
20
|
|
|
21
|
-
A
|
|
21
|
+
A bundle is a package of build products, which may be a single file or multiple files based on a certain [code splitting strategy](https://esbuild.github.io/api/#splitting).
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
bundleless, on the other hand, means that each source file is compiled and built separately, but not bundled together. Each output file can be found with its corresponding source code file. The process of **bundleless build can also be understood as the process of code conversion of source files only**.
|
|
24
24
|
|
|
25
25
|
They have their own benefits.
|
|
26
26
|
|
|
27
|
-
-
|
|
28
|
-
-
|
|
27
|
+
- bundle can reduce the size of build artifacts and also pre-package dependencies to reduce the size of installed dependencies. Packaging libraries in advance can speed up application project builds.
|
|
28
|
+
- bundleless maintains the original file structure and is more conducive to debugging and tree shaking.
|
|
29
29
|
|
|
30
30
|
:::warning
|
|
31
|
-
|
|
31
|
+
bundleless is a single file compilation mode, so for type references and exports you need to add the `type` field, e.g. `import type { A } from '. /types`
|
|
32
32
|
:::
|
|
33
33
|
|
|
34
|
-
In `buildConfig` you can specify whether the current build task is
|
|
34
|
+
In `buildConfig` you can specify whether the current build task is bundle or bundleless by using [`buildConfig.buildType`](/en/api/config/build-config#buildtype).
|
|
35
35
|
|
|
36
|
-
###
|
|
36
|
+
### `input` / `sourceDir`
|
|
37
37
|
|
|
38
|
-
[`buildConfig.input`](/en/api/config/build-config#input) is used to specify the file path or directory path where the source code is read, and its default value differs between
|
|
38
|
+
[`buildConfig.input`](/en/api/config/build-config#input) is used to specify the file path or directory path where the source code is read, and its default value differs between bundle and bundleless builds.
|
|
39
39
|
|
|
40
40
|
- When `buildType: 'bundle'`, `input` defaults to `src/index.(j|t)sx?`
|
|
41
41
|
- When `buildType: 'bundleless'`, `input` defaults to `['src']`
|
|
42
42
|
|
|
43
43
|
:::warning
|
|
44
|
-
It is recommended that you do not specify multiple source file directories during a
|
|
44
|
+
It is recommended that you do not specify multiple source file directories during a bundleless build, as unintended results may occur. bundleless builds with multiple source directories are currently in an unstable stage.
|
|
45
45
|
:::
|
|
46
46
|
|
|
47
|
-
We know from the defaults: **
|
|
47
|
+
We know from the defaults: **bundle builds can generally specify a file path as the entry point to the build, while bundleless builds are more expected to use directory paths to find source files**.
|
|
48
48
|
|
|
49
49
|
#### Object type of `input`
|
|
50
50
|
|
|
51
|
-
In addition to setting `input` to an array, you can also set it to an object during the
|
|
51
|
+
In addition to setting `input` to an array, you can also set it to an object during the bundle build process. **By using the object form, we can modify the name of the file that the build artifacts outputs**. So for the following example, `. /src/index.ts` corresponds to the path of the build artifacts file as `. /dist/main.js`.
|
|
52
52
|
|
|
53
53
|
```js title="modern.config.ts"
|
|
54
54
|
import { defineConfig } from '@modern-js/module-tools';
|
|
@@ -63,7 +63,7 @@ export default defineConfig({
|
|
|
63
63
|
});
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
The
|
|
66
|
+
The bundleless build process also supports such use, but it is not recommended.
|
|
67
67
|
|
|
68
68
|
#### `sourceDir`
|
|
69
69
|
|
|
@@ -74,10 +74,10 @@ The Bundleless build process also supports such use, but it is not recommended.
|
|
|
74
74
|
|
|
75
75
|
In general:
|
|
76
76
|
|
|
77
|
-
- **During the
|
|
78
|
-
- It is rarely necessary to use `sourceDir` during the
|
|
77
|
+
- **During the bundleless build process, the values of `sourceDir` and `input` should be the same, and their default values are both `src`**.
|
|
78
|
+
- It is rarely necessary to use `sourceDir` during the bundle build process.
|
|
79
79
|
|
|
80
|
-
###
|
|
80
|
+
### dts
|
|
81
81
|
|
|
82
82
|
The [`buildConfig.dts`](/en/api/config/build-config#dts) configuration is mainly used for type file generation.
|
|
83
83
|
|
|
@@ -110,7 +110,7 @@ The **Module Tools also supports bundling of type files**, although care needs t
|
|
|
110
110
|
|
|
111
111
|
#### Alias Conversion
|
|
112
112
|
|
|
113
|
-
During the
|
|
113
|
+
During the bundleless build process, if an alias appears in the source code, e.g.
|
|
114
114
|
|
|
115
115
|
```js title="./src/index.ts"
|
|
116
116
|
import utils from '@common/utils';
|
|
@@ -121,9 +121,8 @@ Normally, the type files generated with `tsc` will also contain these aliases. H
|
|
|
121
121
|
- Alias conversion is possible for code of the form `import '@common/utils'` or `import utils from '@common/utils'`.
|
|
122
122
|
- Aliasing is possible for code of the form `export { utils } from '@common/utils'`.
|
|
123
123
|
|
|
124
|
-
However, there are some cases that cannot be handled at this time.
|
|
125
|
-
|
|
126
|
-
- Output types of the form `Promise<import('@common/utils')>` cannot be converted at this time.
|
|
124
|
+
However, there are some cases that cannot be handled at this time.Output types of the form `Promise<import('@common/utils')>` cannot be converted at this time.
|
|
125
|
+
You can discuss it [here](https://github.com/web-infra-dev/modern.js/discussions/4511)
|
|
127
126
|
|
|
128
127
|
#### Some examples of the use of `dts`
|
|
129
128
|
|
|
@@ -240,8 +239,8 @@ declare const YOUR_ADD_GLOBAL_VAR;
|
|
|
240
239
|
When the `modern build` command is executed, the
|
|
241
240
|
|
|
242
241
|
- Clear the output directory according to `buildConfig.outDir`.
|
|
243
|
-
- Compile `js/ts` source code to generate the JS build artifacts for
|
|
244
|
-
- Generate
|
|
242
|
+
- Compile `js/ts` source code to generate the JS build artifacts for bundle/bundleless.
|
|
243
|
+
- Generate bundle/bundleless type files using `tsc`.
|
|
245
244
|
- Handle Copy tasks.
|
|
246
245
|
|
|
247
246
|
## Build errors
|
|
@@ -272,7 +271,7 @@ bundle DTS failed:
|
|
|
272
271
|
|
|
273
272
|
For `js/ts` build errors, we can tell from the error message.
|
|
274
273
|
|
|
275
|
-
- By `'bundle failed:'` to determine if the error is reported for a
|
|
276
|
-
- What is the `format` of the build process
|
|
277
|
-
- What is the `target` of the build process
|
|
278
|
-
- The specific error message
|
|
274
|
+
- By `'bundle failed:'` to determine if the error is reported for a bundle build or a bundleless build
|
|
275
|
+
- What is the `format` of the build process
|
|
276
|
+
- What is the `target` of the build process
|
|
277
|
+
- The specific error message
|
|
@@ -21,7 +21,7 @@ In addition to the `dev` command, you can also start a debugging tool or task di
|
|
|
21
21
|
If you need to extend the dev command, or rather provide your own Module Tools debugging tool plugin, then you will need to know the following first.
|
|
22
22
|
|
|
23
23
|
* [Development of plugins](plugins/guide/getting-started)
|
|
24
|
-
* [Debugging Tools Plugin API](/api/plugin-api/plugin-hooks
|
|
24
|
+
* [Debugging Tools Plugin API](/api/plugin-api/plugin-hooks#dev-hooks)
|
|
25
25
|
|
|
26
26
|
In general, the code to implement a debugging tool that does nothing and the associated configuration is as follows.
|
|
27
27
|
|
|
@@ -90,7 +90,7 @@ In addition to the `"main"` attribute, the `"module"` attribute is usually set.
|
|
|
90
90
|
|
|
91
91
|
> To learn more about how webpack does this, check out this [link](https://webpack.js.org/configuration/resolve/#resolvemainfields).
|
|
92
92
|
|
|
93
|
-
### `
|
|
93
|
+
### `scripts`
|
|
94
94
|
|
|
95
95
|
The `"scripts"` attribute of the `package.json` file supports a number of built-in scripts and npm-preset lifecycle events, as well as arbitrary scripts.
|
|
96
96
|
|