Skip to content

Commit

Permalink
fix(pack): support async postcss plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Stenin authored and yarastqt committed Oct 8, 2020
1 parent 2d63c12 commit 7e1d45f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/pack/src/plugins/CssPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ class CssPlugin implements Plugin {
const files = await glob(this.options.src, { cwd: ctx, ignore: this.options.ignore })
for (const file of files) {
const rawContent = await readFile(resolve(ctx, file), 'utf-8')
const content = this.availableCssProcessor(processor)
? processor.process(rawContent, { from: '', to: '' })
: rawContent
const content = await this.runCssProcessorIfAvailable(rawContent, processor)
const dirs = this.options.output ? this.options.output : [output]
for (const dir of dirs) {
const destPath = resolve(context, dir, file)
Expand All @@ -59,6 +57,14 @@ class CssPlugin implements Plugin {
done()
}

private runCssProcessorIfAvailable(rawContent: string, processor?: Processor) {
if (this.availableCssProcessor(processor)) {
return processor.process(rawContent, { from: '', to: '' }).then((result) => result.css)
}

return Promise.resolve(rawContent)
}

private availableCssProcessor(_p?: Processor): _p is Processor {
return this.options.postcssConfigPath !== undefined
}
Expand Down

0 comments on commit 7e1d45f

Please sign in to comment.