Skip to content

Commit ea5ae68

Browse files
committed
fix(@angular-devkit/build-angular): bring back style tags in browser builder
(cherry picked from commit d746de5)
1 parent 9e6ab1b commit ea5ae68

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

packages/angular/build/src/builders/application/tests/behavior/stylesheet_autoprefixer_spec.ts

+55
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,60 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
200200

201201
harness.expectFile('dist/browser/main.js').content.toMatch(/{\\n\s*hyphens:\s*none;\\n\s*}/);
202202
});
203+
204+
it('should add prefixes for listed browsers in inline template styles', async () => {
205+
await harness.writeFile(
206+
'.browserslistrc',
207+
`
208+
Safari 15.4
209+
Edge 104
210+
Firefox 91
211+
`,
212+
);
213+
214+
await harness.modifyFile('src/app/app.component.ts', (content) => {
215+
return content.replace('styleUrls', 'styles').replace('./app.component.css', '');
216+
});
217+
await harness.modifyFile('src/app/app.component.html', (content) => {
218+
return `<style>aside { hyphens: none; }</style>\n${content}`;
219+
});
220+
221+
harness.useTarget('build', {
222+
...BASE_OPTIONS,
223+
});
224+
225+
const { result } = await harness.executeOnce();
226+
expect(result?.success).toBeTrue();
227+
228+
harness
229+
.expectFile('dist/browser/main.js')
230+
// div[_ngcontent-%COMP%] {\n -webkit-hyphens: none;\n hyphens: none;\n}\n
231+
.content.toMatch(/{\\n\s*-webkit-hyphens:\s*none;\\n\s*hyphens:\s*none;\\n\s*}/);
232+
});
233+
234+
it('should not add prefixes if not required by browsers in inline template styles', async () => {
235+
await harness.writeFile(
236+
'.browserslistrc',
237+
`
238+
Edge 110
239+
`,
240+
);
241+
242+
await harness.modifyFile('src/app/app.component.ts', (content) => {
243+
return content.replace('styleUrls', 'styles').replace('./app.component.css', '');
244+
});
245+
await harness.modifyFile('src/app/app.component.html', (content) => {
246+
return `<style>aside { hyphens: none; }</style>\n${content}`;
247+
});
248+
249+
harness.useTarget('build', {
250+
...BASE_OPTIONS,
251+
});
252+
253+
const { result } = await harness.executeOnce();
254+
expect(result?.success).toBeTrue();
255+
256+
harness.expectFile('dist/browser/main.js').content.toMatch(/{\\n\s*hyphens:\s*none;\\n\s*}/);
257+
});
203258
});
204259
});

packages/angular_devkit/build_angular/src/builders/browser/specs/styles_spec.ts

+31
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,37 @@ describe('Browser Builder styles', () => {
140140
expect(await files['main.js']).toContain('-webkit-mask-composite');
141141
});
142142

143+
it('supports autoprefixer with inline template styles in AOT mode', async () => {
144+
host.writeMultipleFiles({
145+
'./src/app/app.component.html': `
146+
<style>div { mask-composite: add; }</style>
147+
<div>{{ title }}</div>
148+
`,
149+
'./src/app/app.component.ts': `
150+
import { Component } from '@angular/core';
151+
152+
@Component({
153+
selector: 'app-root',
154+
standalone: false,
155+
templateUrl: './app.component.html',
156+
styles: 'div { font-weight: 500; }',
157+
})
158+
export class AppComponent {
159+
title = 'app';
160+
}
161+
`,
162+
'.browserslistrc': `
163+
Safari 15.4
164+
Edge 104
165+
Firefox 91
166+
`,
167+
});
168+
169+
const { files } = await browserBuild(architect, host, target, { aot: true });
170+
171+
expect(await files['main.js']).toContain('-webkit-mask-composite');
172+
});
173+
143174
extensionsWithImportSupport.forEach((ext) => {
144175
it(`supports imports in ${ext} files`, async () => {
145176
host.writeMultipleFiles({

packages/ngtools/webpack/src/ivy/host.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function augmentHostWithResources(
3838

3939
resourceLoader.setAffectedResources(filePath, [filePath]);
4040

41-
return content;
41+
return Promise.resolve(content);
4242
} else {
4343
return resourceLoader.get(filePath);
4444
}

0 commit comments

Comments
 (0)