- svg 設置屬性 fill 為 currentColor
- path 不設置屬性 fill
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 16 16">
<path d="M13 7H3v1h10V7z" />
</svg>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16">
<path fill="#546174" d="M13 7H3v1h10V7z" />
</svg>
const fs = require('fs');
const path = require('path');
const { cwd } = require('process');
// 定義svg資源文件路徑
const iconPath = path.join(cwd(), 'src/svgs');
const parseSVG = (iconPath) => {
const iconFolders = fs.readdirSync(iconPath);
for (const iconFolder of iconFolders) {
const iconDir = path.join(iconPath, iconFolder);
if (fs.statSync(iconDir).isDirectory()) {
parseSVG(iconDir);
continue;
}
// 僅處理.svg 文件
if (path.extname(iconDir) !== '.svg') continue;
let iconData = fs.readFileSync(iconDir, 'utf8');
iconData = iconData.replace(/ fill="#([\da-fA-F]{3,6})"/g, '');
iconData = iconData.replace('fill="none"', 'fill="currentColor"');
fs.writeFileSync(iconDir, iconData);
}
};
parseSVG(iconPath);
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者