You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/document/builder-doc/docs/en/config/output/filename.md
+24-3Lines changed: 24 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,9 +37,9 @@ const prodDefaultFilename = {
37
37
38
38
Sets the filename of dist files.
39
39
40
-
After the production build, there will be a hash in the middle of the filename by default. You can disable this behavior through the `output.disableFilenameHash` config.
40
+
After the production build, there will be a hash in the middle of the filename by default. This behavior can be disabled through the `output.disableFilenameHash` config.
41
41
42
-
Detail:
42
+
The following are the details of each filename:
43
43
44
44
-`js`: The name of the JavaScript file.
45
45
-`css`: The name of the CSS style file.
@@ -50,7 +50,7 @@ Detail:
50
50
51
51
### Example
52
52
53
-
Set the name of the JavaScript file to `[name]_script.js`:
53
+
To set the name of the JavaScript file to `[name]_script.js`, use the following configuration:
54
54
55
55
```js
56
56
exportdefault {
@@ -64,3 +64,24 @@ export default {
64
64
},
65
65
};
66
66
```
67
+
68
+
### Filename of Async Modules
69
+
70
+
When you import a module via dynamic import, the module will be bundled into a single file, and its default naming rules are as follows:
71
+
72
+
- In the development environment, the filename will be generated based on the module path, such as `dist/static/js/async/src_add_ts.js`.
73
+
- In the production environment, it will be a random numeric id, such as `dist/static/js/async/798.27e3083e.js`. This is to avoid leaking the source code path in the production environment, and the number of characters is also less.
74
+
75
+
```js title="src/index.ts"
76
+
const { add } =awaitimport('./add.ts');
77
+
```
78
+
79
+
If you want to specify a fixed name for the async module, you can use the [magic comments](https://webpack.js.org/api/module-methods/#magic-comments) provided by the bundler to achieve this, using `webpackChunkName ` to specify the module name:
80
+
81
+
```js title="src/index.ts"
82
+
const { add } =awaitimport(
83
+
/* webpackChunkName: "my-chunk-name" */'./add.ts'
84
+
);
85
+
```
86
+
87
+
After specifying the module name as above, the generated file will be `dist/static/js/async/my-chunk-name.js`.
0 commit comments