|
8 | 8 | import * as cssNano from 'cssnano';
|
9 | 9 | import { ProcessOptions, Result } from 'postcss';
|
10 | 10 | import { Compilation, Compiler, sources } from 'webpack';
|
11 |
| -import { addWarning } from '../../utils/webpack-diagnostics'; |
| 11 | +import { addError, addWarning } from '../../utils/webpack-diagnostics'; |
12 | 12 |
|
13 | 13 | export interface OptimizeCssWebpackPluginOptions {
|
14 | 14 | sourceMap: boolean;
|
@@ -86,33 +86,39 @@ export class OptimizeCssWebpackPlugin {
|
86 | 86 | map: map && { annotation: false, prev: map },
|
87 | 87 | };
|
88 | 88 |
|
89 |
| - const output = await new Promise<Result>((resolve, reject) => { |
90 |
| - // @types/cssnano are not up to date with version 5. |
91 |
| - // tslint:disable-next-line: no-any |
92 |
| - (cssNano as any)(cssNanoOptions).process(content, postCssOptions) |
93 |
| - .then(resolve) |
94 |
| - .catch((err: Error) => reject(new Error(`${file} ${err.message}`))); |
95 |
| - }); |
96 |
| - |
97 |
| - for (const { text } of output.warnings()) { |
98 |
| - addWarning(compilation, text); |
99 |
| - } |
100 |
| - |
101 |
| - let newSource; |
102 |
| - if (output.map) { |
103 |
| - newSource = new sources.SourceMapSource( |
104 |
| - output.css, |
105 |
| - file, |
| 89 | + try { |
| 90 | + const output = await new Promise<Result>((resolve, reject) => { |
| 91 | + // @types/cssnano are not up to date with version 5. |
106 | 92 | // tslint:disable-next-line: no-any
|
107 |
| - output.map.toString() as any, |
108 |
| - content, |
109 |
| - map, |
110 |
| - ); |
111 |
| - } else { |
112 |
| - newSource = new sources.RawSource(output.css); |
113 |
| - } |
| 93 | + (cssNano as any)(cssNanoOptions).process(content, postCssOptions) |
| 94 | + .then(resolve) |
| 95 | + .catch((err: Error) => reject(err)); |
| 96 | + }); |
| 97 | + |
| 98 | + |
| 99 | + for (const { text } of output.warnings()) { |
| 100 | + addWarning(compilation, text); |
| 101 | + } |
| 102 | + |
| 103 | + let newSource; |
| 104 | + if (output.map) { |
| 105 | + newSource = new sources.SourceMapSource( |
| 106 | + output.css, |
| 107 | + file, |
| 108 | + output.map.toString(), |
| 109 | + content, |
| 110 | + map, |
| 111 | + ); |
| 112 | + } else { |
| 113 | + newSource = new sources.RawSource(output.css); |
| 114 | + } |
| 115 | + |
| 116 | + compilation.assets[file] = newSource; |
| 117 | + } catch (error) { |
| 118 | + addError(compilation, error.message); |
114 | 119 |
|
115 |
| - compilation.assets[file] = newSource; |
| 120 | + return; |
| 121 | + } |
116 | 122 | });
|
117 | 123 |
|
118 | 124 | return Promise.all(actions).then(() => {});
|
|
0 commit comments