Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular-devkit/build-angular): recover from CSS optimization errors #20572

Merged
merged 1 commit into from Apr 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -8,7 +8,7 @@
import * as cssNano from 'cssnano';
import { ProcessOptions, Result } from 'postcss';
import { Compilation, Compiler, sources } from 'webpack';
import { addWarning } from '../../utils/webpack-diagnostics';
import { addError, addWarning } from '../../utils/webpack-diagnostics';

export interface OptimizeCssWebpackPluginOptions {
sourceMap: boolean;
Expand Down Expand Up @@ -86,33 +86,39 @@ export class OptimizeCssWebpackPlugin {
map: map && { annotation: false, prev: map },
};

const output = await new Promise<Result>((resolve, reject) => {
// @types/cssnano are not up to date with version 5.
// tslint:disable-next-line: no-any
(cssNano as any)(cssNanoOptions).process(content, postCssOptions)
.then(resolve)
.catch((err: Error) => reject(new Error(`${file} ${err.message}`)));
});

for (const { text } of output.warnings()) {
addWarning(compilation, text);
}

let newSource;
if (output.map) {
newSource = new sources.SourceMapSource(
output.css,
file,
try {
const output = await new Promise<Result>((resolve, reject) => {
// @types/cssnano are not up to date with version 5.
// tslint:disable-next-line: no-any
output.map.toString() as any,
content,
map,
);
} else {
newSource = new sources.RawSource(output.css);
}
(cssNano as any)(cssNanoOptions).process(content, postCssOptions)
.then(resolve)
.catch((err: Error) => reject(err));
});


for (const { text } of output.warnings()) {
addWarning(compilation, text);
}

let newSource;
if (output.map) {
newSource = new sources.SourceMapSource(
output.css,
file,
output.map.toString(),
content,
map,
);
} else {
newSource = new sources.RawSource(output.css);
}

compilation.assets[file] = newSource;
} catch (error) {
addError(compilation, error.message);

compilation.assets[file] = newSource;
return;
}
});

return Promise.all(actions).then(() => {});
Expand Down