feat: make build option more flexible (#364)

* feat(): allow to disable esbuild bundle option

* feat(): allow to add clean patterns

* Update index.ts

Co-authored-by: EGOIST <0x142857@gmail.com>
This commit is contained in:
Pong 2021-08-04 23:44:49 +08:00 committed by GitHub
parent 405e165ef7
commit d5d2f77e77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -91,7 +91,7 @@ export type Options = {
/**
* Clean output directory before each build
*/
clean?: boolean
clean?: boolean | string[];
esbuildPlugins?: EsbuildPlugin[]
/**
* Supress non-error logs (excluding "onSuccess" process output)
@ -105,6 +105,10 @@ export type Options = {
* @see https://esbuild.github.io/api/#pure
*/
pure?: string | string[]
/**
* Disable bunlding, default to true
*/
bundle?: boolean
}
export type NormalizedOptions = MarkRequired<
@ -167,7 +171,7 @@ export async function runEsbuild(
result = await esbuild({
entryPoints: options.entryPoints,
format: splitting && format === 'cjs' ? 'esm' : format,
bundle: true,
bundle: typeof options.bundle === 'undefined' ? true : options.bundle,
platform: 'node',
globalName: options.globalName,
jsxFactory: options.jsxFactory,
@ -407,7 +411,8 @@ export async function build(_options: Options) {
const killPromise = killPreviousProcess()
if (options.clean) {
await removeFiles(['**/*', '!**/*.d.ts'], options.outDir)
const extraPatterns = Array.isArray(options.clean) ? options.clean : []
await removeFiles(['**/*', '!**/*.d.ts', ...extraPatterns], options.outDir)
log('CLI', 'info', 'Cleaning output folder')
}