Sha256: 261440c882e0314447e6e500ac7fe19c151859267507b2a0a87faec0448fc56e
Contents?: true
Size: 1.73 KB
Versions: 36
Compression:
Stored size: 1.73 KB
Contents
import { optimize } from "svgo"; import fs from "fs/promises"; import { existsSync, mkdirSync } from "fs"; import prettier from "prettier"; export default function (sourcePath, destPath, configPath) { return { name: "optimize-icons", setup(build) { build.onEnd(async (result) => { const files = await fs.readdir(sourcePath); const iconNames = []; if (!existsSync(destPath)) { mkdirSync(destPath); } await Promise.all( files .filter((fileName) => fileName.endsWith(".svg")) .map(async (fileName) => { const filePath = `${sourcePath}/${fileName}`; const svgText = await fs.readFile(filePath, { encoding: "utf8", }); const optimizedSvg = optimize(svgText, { path: filePath, plugins: [ { name: "removeAttrs", params: { attrs: "(fill|stroke|stroke-width|stroke-linecap|stroke-linejoin)", }, }, ], }); await fs.writeFile(`${destPath}/${fileName}`, optimizedSvg.data); iconNames.push(fileName.replace(".svg", "")); }) ); const iconsDataFilePath = `${configPath}/icons.json`; prettier.resolveConfig(iconsDataFilePath).then(async (options) => { const formattedJSON = prettier.format( JSON.stringify(iconNames.sort()), { ...options, parser: "json", } ); await fs.writeFile(iconsDataFilePath, formattedJSON); }); }); }, }; }
Version data entries
36 entries across 36 versions & 1 rubygems