Skip to content

Commit b277030

Browse files
alan-agius4dgp1130
authored andcommitted
fix(@angular-devkit/build-angular): fix autoprefixer comments support in scss
Change Scss output style to `expanded` as otherwise sass will remove comments that are needed for autoprefixer when webpack is in prod mode because of the following implementation in `sass-loader`: See: https://github.com/webpack-contrib/sass-loader/blob/45ad0be17264ceada5f0b4fb87e9357abe85c4ff/src/getSassOptions.js#L68-L70 Fixes #17041 (cherry picked from commit d29d403)
1 parent bb7cf7f commit b277030

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/styles.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
136136
// bootstrap-sass requires a minimum precision of 8
137137
precision: 8,
138138
includePaths,
139+
// Use expanded as otherwise sass will remove comments that are needed for autoprefixer
140+
// Ex: /* autoprefixer grid: autoplace */
141+
// tslint:disable-next-line: max-line-length
142+
// See: https://github.com/webpack-contrib/sass-loader/blob/45ad0be17264ceada5f0b4fb87e9357abe85c4ff/src/getSassOptions.js#L68-L70
143+
outputStyle: 'expanded',
139144
},
140145
},
141146
},

packages/angular_devkit/build_angular/test/browser/styles_spec_large.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,24 @@ describe('Browser Builder styles', () => {
309309
expect(await files['styles.css']).toContain('/*! important-comment */div{flex:1}');
310310
});
311311

312+
it('supports autoprefixer grid comments in SCSS with optimization true', async () => {
313+
host.writeMultipleFiles({
314+
'src/styles.scss': tags.stripIndents`
315+
/* autoprefixer grid: autoplace */
316+
.css-grid-container {
317+
display: grid;
318+
row-gap: 10px;
319+
grid-template-columns: 100px;
320+
}
321+
`,
322+
browserslist: 'IE 10',
323+
});
324+
325+
const overrides = { extractCss: true, optimization: true, styles: ['src/styles.scss'] };
326+
const { files } = await browserBuild(architect, host, target, overrides);
327+
expect(await files['styles.css']).toContain('-ms-grid-columns:100px;');
328+
});
329+
312330
// TODO: consider making this a unit test in the url processing plugins.
313331
it(`supports baseHref/deployUrl in resource urls without rebaseRootRelativeCssUrls`, async () => {
314332
// Use a large image for the relative ref so it cannot be inlined.

0 commit comments

Comments
 (0)