Skip to content

Commit ef79681

Browse files
committed
docs: output.filename.css allow function(#3701)
1 parent ed20ecf commit ef79681

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

website/docs/en/config/output/filename.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ After specifying the module name as above, the generated file will be `dist/stat
128128

129129
## Using Function
130130

131-
You can pass a function to `output.filename.js`, allowing you to dynamically generate filenames based on file information:
131+
You can pass a function to `output.filename.js` or `output.filename.css`, allowing you to dynamically generate filenames based on file information:
132132

133133
```js
134134
export default {
@@ -144,6 +144,14 @@ export default {
144144

145145
return '/some-path/[name].js';
146146
},
147+
css: (pathData, assetInfo) => {
148+
if (pathData.chunk?.name === 'index') {
149+
const isProd = process.env.NODE_ENV === 'production';
150+
return isProd ? '[name].[contenthash:8].css' : '[name].css';
151+
}
152+
153+
return '/some-path/[name].css';
154+
},
147155
},
148156
},
149157
};

website/docs/zh/config/output/filename.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const { add } = await import(
129129

130130
## 使用函数
131131

132-
`output.filename.js` 可以传入一个函数,这允许你根据文件信息动态生成文件名:
132+
`output.filename.js` `output.filename.css` 可以传入一个函数,这允许你根据文件信息动态生成文件名:
133133

134134
```js
135135
export default {
@@ -145,6 +145,14 @@ export default {
145145

146146
return '/some-path/[name].js';
147147
},
148+
css: (pathData, assetInfo) => {
149+
if (pathData.chunk?.name === 'index') {
150+
const isProd = process.env.NODE_ENV === 'production';
151+
return isProd ? '[name].[contenthash:8].css' : '[name].css';
152+
}
153+
154+
return '/some-path/[name].css';
155+
},
148156
},
149157
},
150158
};

0 commit comments

Comments
 (0)