我有这个规则,使用 vue inspect
/* config.module.rule('svg') */
{
test: /\.(svg)(\?.*)?$/,
type: 'asset/resource',
generator: {
filename: 'img/[name][ext]'
}
},
我需要将文件名更改为“[contenthash][ext]” 但我不能用
module.exports = defineConfig({
chainWebpack: (config) => {
config.module.rule("svg").generator.filename = "[contenthash][ext]";
},
})
因为我不能设置生成器,
我可以使用重写所有规则
module.exports = defineConfig({
configureWebpack: (config) => {
config.module.rules = [
{
test: /\.(svg)(\?.*)?$/,
use: [
{
loader: "svg-inline-loader",
options: {
name: "[contenthash].[ext]",
},
},
],
},
];
},
})
但我需要存在其他规则...那么如何更改 svg 的文件名?
最佳答案
试试这个:
chainWebpack: (config) => {
config.module.rule("svg")
.set('generator', {
filename: "[contenthash][ext]"
})
}
关于vue.js - 如何更改规则内的文件名? (Vue CLI 5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70089727/