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: website/docs/en/guide/faq/features.mdx
+27-27Lines changed: 27 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,33 +35,6 @@ export default defineConfig({
35
35
});
36
36
```
37
37
38
-
## Output related
39
-
40
-
### How to preserve module variables such as `__webpack_hash__` in the source code when generating outputs?
41
-
42
-
Rslib based on Rspack will transform [module variables](https://rspack.dev/api/runtime-api/module-variables) like `__webpack_hash__`, `__webpack_nonce__`, `__webpack_public_path__`, etc. to runtime code containing `__webpack_require__` by default during build process. If you need to preserve these module variables in the outputs, you can configure [source.define](/config/rsbuild/source#sourcedefine) as follows:
43
-
44
-
1. Replace the module variables that need to be preserved in the source code with a unique name, such as `__webpack_hash__` with `WEBPACK_HASH`, `__webpack_nonce__` with `WEBPACK_NONCE`, `__webpack_public_path__` with `WEBPACK_PUBLIC_PATH`, etc.
2. Add the module variables that need to be preserved in `source.define`. The key of the passed configuration object is the replaced variable name in the source code, and the value is the module variable that needs to be preserved in the outputs.
52
-
53
-
```ts title="rslib.config.ts"
54
-
exportdefaultdefineConfig({
55
-
source: {
56
-
define: {
57
-
WEBPACK_HASH: '__webpack_hash__',
58
-
WEBPACK_NONCE: '__webpack_nonce__',
59
-
WEBPACK_PUBLIC_PATH: '__webpack_public_path__',
60
-
},
61
-
},
62
-
});
63
-
```
64
-
65
38
## Code minification
66
39
67
40
### How to preserve all comments in the output files?
@@ -140,3 +113,30 @@ export default {
140
113
},
141
114
};
142
115
```
116
+
117
+
## Others
118
+
119
+
### How to preserve module variables such as `__webpack_hash__` in the source code when generating outputs?
120
+
121
+
Rslib based on Rspack will transform [module variables](https://rspack.dev/api/runtime-api/module-variables) like `__webpack_hash__`, `__webpack_nonce__`, `__webpack_public_path__`, etc. to runtime code containing `__webpack_require__` by default during build process. If you need to preserve these module variables in the outputs, you can configure [source.define](/config/rsbuild/source#sourcedefine) as follows:
122
+
123
+
1. Replace the module variables that need to be preserved in the source code with a unique name, such as `__webpack_hash__` with `WEBPACK_HASH`, `__webpack_nonce__` with `WEBPACK_NONCE`, `__webpack_public_path__` with `WEBPACK_PUBLIC_PATH`, etc.
2. Add the module variables that need to be preserved in `source.define`. The key of the passed configuration object is the replaced variable name in the source code, and the value is the module variable that needs to be preserved in the outputs.
0 commit comments