Skip to content

Commit be97daa

Browse files
committed
chore: update
1 parent 9e2dad6 commit be97daa

File tree

2 files changed

+54
-54
lines changed

2 files changed

+54
-54
lines changed

website/docs/en/guide/faq/features.mdx

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,6 @@ export default defineConfig({
3535
});
3636
```
3737

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.
45-
46-
```ts
47-
const isUpdateAvailable = () => lastCompilationHash !== __webpack_hash__; // [!code --]
48-
const isUpdateAvailable = () => lastCompilationHash !== WEBPACK_HASH; // [!code ++]
49-
```
50-
51-
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-
export default defineConfig({
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-
6538
## Code minification
6639

6740
### How to preserve all comments in the output files?
@@ -140,3 +113,30 @@ export default {
140113
},
141114
};
142115
```
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.
124+
125+
```ts
126+
const isUpdateAvailable = () => lastCompilationHash !== __webpack_hash__; // [!code --]
127+
const isUpdateAvailable = () => lastCompilationHash !== WEBPACK_HASH; // [!code ++]
128+
```
129+
130+
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.
131+
132+
```ts title="rslib.config.ts"
133+
export default defineConfig({
134+
source: {
135+
define: {
136+
WEBPACK_HASH: '__webpack_hash__',
137+
WEBPACK_NONCE: '__webpack_nonce__',
138+
WEBPACK_PUBLIC_PATH: '__webpack_public_path__',
139+
},
140+
},
141+
});
142+
```

website/docs/zh/guide/faq/features.mdx

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,6 @@ export default defineConfig({
3535
});
3636
```
3737

38-
## 产物相关
39-
40-
### 如何在生成产物时保留源码中的 `__webpack_hash__` 等模块变量?
41-
42-
Rslib 底层使用的 Rspack,在构建时会默认将 `__webpack_hash__``__webpack_nonce__``__webpack_public_path__`[模块变量](https://rspack.dev/zh/api/runtime-api/module-variables) 转换为包含 `__webpack_require__` 的运行时代码。如果你需要在产物中保留这些模块变量,可以通过配置 [source.define](/config/rsbuild/source#sourcedefine) 来实现,如下所示:
43-
44-
1. 在源码中将需要保留的模块变量替换为一个特征名称,如 `__webpack_hash__` 替换为 `WEBPACK_HASH``__webpack_nonce__` 替换为 `WEBPACK_NONCE``__webpack_public_path__` 替换为 `WEBPACK_PUBLIC_PATH` 等。
45-
46-
```ts
47-
const isUpdateAvailable = () => lastCompilationHash !== __webpack_hash__; // [!code --]
48-
const isUpdateAvailable = () => lastCompilationHash !== WEBPACK_HASH; // [!code ++]
49-
```
50-
51-
2.`source.define` 中添加需要保留的模块变量,传入的配置对象的键名是源码中替换后的变量名称,值是需要在产物中保留的模块变量。
52-
53-
```ts title="rslib.config.ts"
54-
export default defineConfig({
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-
6538
## 代码压缩
6639

6740
### 如何保留产物文件代码中的注释?
@@ -140,3 +113,30 @@ export default {
140113
},
141114
};
142115
```
116+
117+
## 其他
118+
119+
### 如何在生成产物时保留源码中的 `__webpack_hash__` 等模块变量?
120+
121+
Rslib 底层使用的 Rspack,在构建时会默认将 `__webpack_hash__``__webpack_nonce__``__webpack_public_path__`[模块变量](https://rspack.dev/zh/api/runtime-api/module-variables) 转换为包含 `__webpack_require__` 的运行时代码。如果你需要在产物中保留这些模块变量,可以通过配置 [source.define](/config/rsbuild/source#sourcedefine) 来实现,如下所示:
122+
123+
1. 在源码中将需要保留的模块变量替换为一个特征名称,如 `__webpack_hash__` 替换为 `WEBPACK_HASH``__webpack_nonce__` 替换为 `WEBPACK_NONCE``__webpack_public_path__` 替换为 `WEBPACK_PUBLIC_PATH` 等。
124+
125+
```ts
126+
const isUpdateAvailable = () => lastCompilationHash !== __webpack_hash__; // [!code --]
127+
const isUpdateAvailable = () => lastCompilationHash !== WEBPACK_HASH; // [!code ++]
128+
```
129+
130+
2.`source.define` 中添加需要保留的模块变量,传入的配置对象的键名是源码中替换后的变量名称,值是需要在产物中保留的模块变量。
131+
132+
```ts title="rslib.config.ts"
133+
export default defineConfig({
134+
source: {
135+
define: {
136+
WEBPACK_HASH: '__webpack_hash__',
137+
WEBPACK_NONCE: '__webpack_nonce__',
138+
WEBPACK_PUBLIC_PATH: '__webpack_public_path__',
139+
},
140+
},
141+
});
142+
```

0 commit comments

Comments
 (0)