Skip to content

Commit f20d9ac

Browse files
committedJan 31, 2019
feat: add --concurrent mode
1 parent abeaa86 commit f20d9ac

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed
 

‎src/cli.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ cli
4141
.option('--minimal', 'Generate minimal output whenever possible')
4242
.option('--banner', 'Add banner with pkg info to the bundle')
4343
.option('--no-async-pro, --no-async-to-promises', 'Leave async/await as is')
44+
.option('--concurrent', 'Build concurrently')
4445
.option('--verbose', 'Show verbose logs')
4546
.option('--quiet', 'Show minimal logs')
4647
.option('--stack-trace', 'Show stack trace for bundle errors')
@@ -82,7 +83,11 @@ cli
8283
}
8384
)
8485
await bundler
85-
.run({ write: true, watch: options.watch })
86+
.run({
87+
write: true,
88+
watch: options.watch,
89+
concurrent: options.concurrent
90+
})
8691
.catch((err: any) => {
8792
bundler.handleError(err)
8893
process.exit(1)

‎src/index.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ process.env.BUILD = 'production'
4040
interface RunOptions {
4141
write?: boolean
4242
watch?: boolean
43+
concurrent?: boolean
4344
}
4445

4546
interface RunContext {
@@ -340,7 +341,6 @@ export class Bundler {
340341
plugins.push({
341342
name: 'record-bundle',
342343
generateBundle(outputOptions, _assets) {
343-
logger.success(title.replace('Bundle', 'Bundled'))
344344
const EXTS = [
345345
outputOptions.entryFileNames
346346
? path.extname(outputOptions.entryFileNames)
@@ -365,6 +365,7 @@ export class Bundler {
365365
}
366366
},
367367
async writeBundle() {
368+
logger.success(title.replace('Bundle', 'Bundled'))
368369
await printAssets(assets)
369370
}
370371
})
@@ -538,12 +539,20 @@ export class Bundler {
538539
})
539540
} else {
540541
try {
541-
await waterfall(
542-
tasks.map(task => () => {
543-
return this.build(task, context, options.write)
544-
}),
545-
context
546-
)
542+
if (options.concurrent) {
543+
await Promise.all(
544+
tasks.map(task => {
545+
return this.build(task, context, options.write)
546+
})
547+
)
548+
} else {
549+
await waterfall(
550+
tasks.map(task => () => {
551+
return this.build(task, context, options.write)
552+
}),
553+
context
554+
)
555+
}
547556
} catch (err) {
548557
spinner.stop()
549558
throw err

0 commit comments

Comments
 (0)
Please sign in to comment.