Skip to content

Commit 7e1d45f

Browse files
Nikita Steninyarastqt
authored andcommitted
fix(pack): support async postcss plugins
1 parent 2d63c12 commit 7e1d45f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/pack/src/plugins/CssPlugin.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ class CssPlugin implements Plugin {
4545
const files = await glob(this.options.src, { cwd: ctx, ignore: this.options.ignore })
4646
for (const file of files) {
4747
const rawContent = await readFile(resolve(ctx, file), 'utf-8')
48-
const content = this.availableCssProcessor(processor)
49-
? processor.process(rawContent, { from: '', to: '' })
50-
: rawContent
48+
const content = await this.runCssProcessorIfAvailable(rawContent, processor)
5149
const dirs = this.options.output ? this.options.output : [output]
5250
for (const dir of dirs) {
5351
const destPath = resolve(context, dir, file)
@@ -59,6 +57,14 @@ class CssPlugin implements Plugin {
5957
done()
6058
}
6159

60+
private runCssProcessorIfAvailable(rawContent: string, processor?: Processor) {
61+
if (this.availableCssProcessor(processor)) {
62+
return processor.process(rawContent, { from: '', to: '' }).then((result) => result.css)
63+
}
64+
65+
return Promise.resolve(rawContent)
66+
}
67+
6268
private availableCssProcessor(_p?: Processor): _p is Processor {
6369
return this.options.postcssConfigPath !== undefined
6470
}

0 commit comments

Comments
 (0)