Skip to content

Commit

Permalink
feat(father-build): control dist clean by arg (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
3lang3 committed Mar 15, 2022
1 parent 4c24f53 commit e38134e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/father-build/bin/father-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function build() {
.default({
cwd: args.root || process.cwd(),
watch: args.w || args.watch,
clean: args.clean,
buildArgs,
})
.catch((e) => {
Expand Down
11 changes: 7 additions & 4 deletions packages/father-build/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ interface IExtraBuildOpts {
}

export async function build(opts: IOpts, extraOpts: IExtraBuildOpts = {}) {
const { cwd, rootPath, watch, buildArgs = {} } = opts;
const { cwd, rootPath, watch, buildArgs = {}, clean = true } = opts;
const { pkg } = extraOpts;

const dispose: Dispose[] = [];
Expand Down Expand Up @@ -129,8 +129,11 @@ export async function build(opts: IOpts, extraOpts: IExtraBuildOpts = {}) {
validateBundleOpts(bundleOpts, { cwd, rootPath });

// Clean dist
log(chalk.gray(`Clean dist directory`));
rimraf.sync(join(cwd, 'dist'));
if (clean) {
log(chalk.gray(`Clean dist directory`));
rimraf.sync(join(cwd, 'dist'));
}


// Build umd
if (bundleOpts.umd) {
Expand Down Expand Up @@ -245,7 +248,7 @@ export async function buildForLerna(opts: IOpts) {
return dispose;
}

export default async function(opts: IOpts) {
export default async function (opts: IOpts) {
const useLerna = existsSync(join(opts.cwd, 'lerna.json'));
const isLerna = useLerna && process.env.LERNA !== 'none';

Expand Down
5 changes: 5 additions & 0 deletions packages/father-build/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ export interface IBundleOptions {
export interface IOpts {
cwd: string;
watch?: boolean;
/**
* 构建时清空outputDir
* @default true
* */
clean?: boolean;
buildArgs?: IBundleOptions;
rootConfig?: IBundleOptions;
rootPath?: string;
Expand Down

0 comments on commit e38134e

Please sign in to comment.