Skip to content

Commit cc09b70

Browse files
committed
fix(@angular-devkit/build-angular): correctly handle sass imports
Prior to this change nested imports in sass were processed as scss when using the esbuild builder due to an incorrect check. Closes #25338
1 parent aa0baa9 commit cc09b70

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

packages/angular_devkit/build_angular/src/sass/rebasing-importer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ abstract class UrlRebasingImporter implements Importer<'sync'> {
8989

9090
let syntax: Syntax | undefined;
9191
switch (extname(stylesheetPath).toLowerCase()) {
92-
case 'css':
92+
case '.css':
9393
syntax = 'css';
9494
break;
95-
case 'sass':
95+
case '.sass':
9696
syntax = 'indented';
9797
break;
9898
default:
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {
2+
writeMultipleFiles,
3+
deleteFile,
4+
expectFileToMatch,
5+
replaceInFile,
6+
} from '../../../utils/fs';
7+
import { expectToFail } from '../../../utils/utils';
8+
import { ng } from '../../../utils/process';
9+
import { updateJsonFile } from '../../../utils/project';
10+
11+
export default async function () {
12+
await writeMultipleFiles({
13+
'src/styles.sass': `
14+
@import './imported-styles.sass'
15+
body
16+
background-color: blue
17+
`,
18+
'src/imported-styles.sass': `
19+
p
20+
background-color: red
21+
`,
22+
'src/app/app.component.sass': `
23+
.outer
24+
.inner
25+
background: #fff
26+
`,
27+
});
28+
29+
await updateJsonFile('angular.json', (workspaceJson) => {
30+
const appArchitect = workspaceJson.projects['test-project'].architect;
31+
appArchitect.build.options.styles = [{ input: 'src/styles.sass' }];
32+
});
33+
34+
await deleteFile('src/app/app.component.css');
35+
await replaceInFile('src/app/app.component.ts', './app.component.css', './app.component.sass');
36+
37+
await ng('build', '--source-map', '--configuration=development');
38+
39+
await expectFileToMatch('dist/test-project/styles.css', /body\s*{\s*background-color: blue;\s*}/);
40+
await expectFileToMatch('dist/test-project/styles.css', /p\s*{\s*background-color: red;\s*}/);
41+
await expectToFail(() => expectFileToMatch('dist/test-project/styles.css', '"mappings":""'));
42+
await expectFileToMatch('dist/test-project/main.js', /.outer.*.inner.*background:\s*#[fF]+/);
43+
}

0 commit comments

Comments
 (0)