Skip to content

Commit 806447e

Browse files
Charles Lydinghansl
authored andcommitted
fix(@angular/cli): use safer stylesheet minification settings
1 parent 9805010 commit 806447e

File tree

1 file changed

+12
-3
lines changed
  • packages/@angular/cli/models/webpack-configs

1 file changed

+12
-3
lines changed

packages/@angular/cli/models/webpack-configs/styles.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,16 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
4747
const deployUrl = wco.buildOptions.deployUrl || '';
4848

4949
const postcssPluginCreator = function() {
50+
// safe settings based on: https://github.com/ben-eb/cssnano/issues/358#issuecomment-283696193
51+
const importantCommentRe = /@preserve|@license|[@#]\s*source(?:Mapping)?URL|^!/i;
52+
const minimizeOptions = {
53+
autoprefixer: false, // full pass with autoprefixer is run separately
54+
safe: true,
55+
mergeLonghand: false, // version 3+ should be safe; cssnano currently uses 2.x
56+
discardComments : { remove: (comment: string) => !importantCommentRe.test(comment) }
57+
};
58+
5059
return [
51-
autoprefixer(),
5260
postcssUrl({
5361
url: (URL: string) => {
5462
// Only convert root relative URLs, which CSS-Loader won't process into require().
@@ -69,9 +77,10 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
6977
return `/${baseHref}/${deployUrl}/${URL}`.replace(/\/\/+/g, '/');
7078
}
7179
}
72-
})
80+
}),
81+
autoprefixer(),
7382
].concat(
74-
minimizeCss ? [cssnano({ safe: true, autoprefixer: false })] : []
83+
minimizeCss ? [cssnano(minimizeOptions)] : []
7584
);
7685
};
7786
(postcssPluginCreator as any)[postcssArgs] = {

0 commit comments

Comments
 (0)