Skip to content

Commit 6d95d24

Browse files
committed
run generateIcons at startup if sprite.svg does not exist
1 parent 0840952 commit 6d95d24

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,22 @@ export const iconsSpritesheet: (args: PluginProps) => Plugin = ({ withTypes, inp
141141
apply(config) {
142142
return config.mode === "development";
143143
},
144+
async configResolved(config) {
145+
const outputSvgPath = normalizePath(path.join(cwd ?? process.cwd(), outputDir, fileName ?? "sprite.svg"));
146+
if (
147+
!(await fs
148+
.access(outputSvgPath, fs.constants.F_OK)
149+
.then(() => true)
150+
.catch(() => false))
151+
) {
152+
await generateIcons({
153+
withTypes,
154+
inputDir,
155+
outputDir,
156+
fileName,
157+
});
158+
}
159+
},
144160
async watchChange(file, type) {
145161
const inputPath = normalizePath(path.join(cwd ?? process.cwd(), inputDir));
146162
if (file.includes(inputPath) && file.endsWith(".svg") && ["create", "delete"].includes(type.event)) {

0 commit comments

Comments
 (0)