Skip to content

Commit b5d2293

Browse files
committed
feat: clear output directory when building start.
1 parent b805265 commit b5d2293

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/core/unplugin.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ export default createUnplugin<Partial<PluginOptions> | undefined>((userOptions =
5252
Object.keys(opts.collections)
5353
.map(prefix => [
5454
prefix,
55-
resolve(opts.cwd, opts.output, `${prefix}.json`),
55+
isAbsolute(opts.output)
56+
? resolve(opts.output, `${prefix}.json`)
57+
: resolve(opts.cwd, opts.output, `${prefix}.json`),
5658
]),
5759
)
5860

@@ -91,11 +93,19 @@ export default createUnplugin<Partial<PluginOptions> | undefined>((userOptions =
9193
)
9294
}
9395

96+
async function clearOutputDir() {
97+
const outputDir = isAbsolute(opts.output) ? opts.output : resolve(opts.cwd, opts.output)
98+
const isExistOutputDir = await fs.pathExists(outputDir)
99+
isExistOutputDir && await fs.emptyDir(outputDir)
100+
}
101+
94102
let watcher: FSWatcher
95103

96104
return {
97105
name: 'unplugin-iconify-generator',
98106
async buildStart() {
107+
await clearOutputDir()
108+
99109
/**
100110
* antfu.iconify cannot fsWatch a nonexistent file
101111
* so create empty iconifyJSON files first, then update vscode settings

0 commit comments

Comments
 (0)