Skip to content

Commit 5b78029

Browse files
authored
feat: add clean option to clear output path before bundling (#30)
1 parent df47361 commit 5b78029

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

examples/ant-pro/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ screenshot
3939
.eslintcache
4040

4141
build
42+
.takumi/todos

packages/bundler-shared-config/src/provider/BaseBundler.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
Stats,
66
} from '@kmijs/bundler-shared/rspack'
77
import type { Configuration } from '@kmijs/bundler-shared/rspack'
8-
import { logger } from '@kmijs/shared'
8+
import { logger, rimraf } from '@kmijs/shared'
99
import { Env, type IUserConfig } from '../types'
1010
import { esbuildCompressErrorHelper } from '../utils/esbuildCompressErrorHelper'
1111
import type {
@@ -72,6 +72,23 @@ export abstract class BaseBundler<
7272
let isFirstCompile = true
7373

7474
return new Promise((resolve, reject) => {
75+
if (opts.clean) {
76+
bundlerConfigs.forEach((config) => {
77+
if (config.output?.path) {
78+
try {
79+
logger.verbose(
80+
`[BaseBundler] Cleaning output directory: ${config.output.path}`,
81+
)
82+
rimraf.sync(config.output.path)
83+
} catch (error) {
84+
logger.verbose(
85+
`[BaseBundler] Cleaning output directory: ${config.output.path} failed`,
86+
)
87+
}
88+
}
89+
})
90+
}
91+
7592
const compiler = this.createCompiler({
7693
...buildOptions,
7794
bundlerConfigs,

0 commit comments

Comments
 (0)