Skip to content

Commit fe25fb3

Browse files
authored
docs: assets output filename and distPath (#1332)
1 parent 06563fd commit fe25fb3

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

website/docs/en/guide/advanced/static-assets.mdx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,37 @@ When the [format](/config/lib/format) is set to `cjs` or `esm`, Rslib treats the
212212

213213
Once static assets are imported, they will automatically be output to the build output directory. You can:
214214

215-
- Modify the filename of the outputs through [output.filename](/config/rsbuild/output#outputfilename).
216-
- Change the output path of the outputs through [output.distPath](/config/rsbuild/output#outputdistpath).
215+
- Modify the filename of the outputs through [output.filename](/config/rsbuild/output#outputfilename). For example, add a hash value to the filename of the outputs, which is usually used when there are files with the same name to avoid filename conflicts.
216+
217+
```ts title="rslib.config.ts"
218+
export default {
219+
output: {
220+
filename: {
221+
svg: '[name].[contenthash:8].svg',
222+
font: '[name].[contenthash:8][ext]',
223+
image: '[name].[contenthash:8][ext]',
224+
media: '[name].[contenthash:8][ext]',
225+
assets: '[name].[contenthash:8][ext]',
226+
},
227+
},
228+
};
229+
```
230+
231+
- Change the output path of the outputs through [output.distPath](/config/rsbuild/output#outputdistpath). For example, emit static assets output to the `dist/resource` directory.
232+
233+
```ts title="rslib.config.ts"
234+
export default {
235+
output: {
236+
distPath: {
237+
svg: 'resource/svg',
238+
font: 'resource/font',
239+
image: 'resource/image',
240+
media: 'resource/media',
241+
assets: 'resource/assets',
242+
},
243+
},
244+
};
245+
```
217246

218247
## Type declaration
219248

website/docs/zh/guide/advanced/static-assets.mdx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,37 @@ export default {
212212

213213
当静态资源被引用后,会自动被输出到构建产物的目录下,你可以:
214214

215-
- 通过 [output.filename](/config/rsbuild/output#outputfilename) 来修改产物的文件名。
216-
- 通过 [output.distPath](/config/rsbuild/output#outputdistpath) 来修改产物的输出路径。
215+
- 通过 [output.filename](/config/rsbuild/output#outputfilename) 来修改产物的文件名。例如,在产物的文件名中添加 hash 值,这通常在有同名文件时使用,以避免文件名冲突。
216+
217+
```ts title="rslib.config.ts"
218+
export default {
219+
output: {
220+
filename: {
221+
svg: '[name].[contenthash:8].svg',
222+
font: '[name].[contenthash:8][ext]',
223+
image: '[name].[contenthash:8][ext]',
224+
media: '[name].[contenthash:8][ext]',
225+
assets: '[name].[contenthash:8][ext]',
226+
},
227+
},
228+
};
229+
```
230+
231+
- 通过 [output.distPath](/config/rsbuild/output#outputdistpath) 来修改产物的输出路径。例如,将静态资源产物输出到 `dist/resource` 目录下。
232+
233+
```ts title="rslib.config.ts"
234+
export default {
235+
output: {
236+
distPath: {
237+
svg: 'resource/svg',
238+
font: 'resource/font',
239+
image: 'resource/image',
240+
media: 'resource/media',
241+
assets: 'resource/assets',
242+
},
243+
},
244+
};
245+
```
217246

218247
## 类型声明
219248

0 commit comments

Comments
 (0)