Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): bring back style tags in browser …
Browse files Browse the repository at this point in the history
…builder
  • Loading branch information
jkrems committed Nov 18, 2024
1 parent 2e43ec6 commit d746de5
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,60 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {

harness.expectFile('dist/browser/main.js').content.toMatch(/{\\n\s*hyphens:\s*none;\\n\s*}/);
});

it('should add prefixes for listed browsers in inline template styles', async () => {
await harness.writeFile(
'.browserslistrc',
`
Safari 15.4
Edge 104
Firefox 91
`,
);

await harness.modifyFile('src/app/app.component.ts', (content) => {
return content.replace('styleUrls', 'styles').replace('./app.component.css', '');
});
await harness.modifyFile('src/app/app.component.html', (content) => {
return `<style>aside { hyphens: none; }</style>\n${content}`;
});

harness.useTarget('build', {
...BASE_OPTIONS,
});

const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();

harness
.expectFile('dist/browser/main.js')
// div[_ngcontent-%COMP%] {\n -webkit-hyphens: none;\n hyphens: none;\n}\n
.content.toMatch(/{\\n\s*-webkit-hyphens:\s*none;\\n\s*hyphens:\s*none;\\n\s*}/);
});

it('should not add prefixes if not required by browsers in inline template styles', async () => {
await harness.writeFile(
'.browserslistrc',
`
Edge 110
`,
);

await harness.modifyFile('src/app/app.component.ts', (content) => {
return content.replace('styleUrls', 'styles').replace('./app.component.css', '');
});
await harness.modifyFile('src/app/app.component.html', (content) => {
return `<style>aside { hyphens: none; }</style>\n${content}`;
});

harness.useTarget('build', {
...BASE_OPTIONS,
});

const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();

harness.expectFile('dist/browser/main.js').content.toMatch(/{\\n\s*hyphens:\s*none;\\n\s*}/);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,37 @@ describe('Browser Builder styles', () => {
expect(await files['main.js']).toContain('-webkit-mask-composite');
});

it('supports autoprefixer with inline template styles in AOT mode', async () => {
host.writeMultipleFiles({
'./src/app/app.component.html': `
<style>div { mask-composite: add; }</style>
<div>{{ title }}</div>
`,
'./src/app/app.component.ts': `
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
standalone: false,
templateUrl: './app.component.html',
styles: 'div { font-weight: 500; }',
})
export class AppComponent {
title = 'app';
}
`,
'.browserslistrc': `
Safari 15.4
Edge 104
Firefox 91
`,
});

const { files } = await browserBuild(architect, host, target, { aot: true });

expect(await files['main.js']).toContain('-webkit-mask-composite');
});

extensionsWithImportSupport.forEach((ext) => {
it(`supports imports in ${ext} files`, async () => {
host.writeMultipleFiles({
Expand Down
2 changes: 1 addition & 1 deletion packages/ngtools/webpack/src/ivy/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function augmentHostWithResources(

resourceLoader.setAffectedResources(filePath, [filePath]);

return content;
return Promise.resolve(content);
} else {
return resourceLoader.get(filePath);
}
Expand Down

0 comments on commit d746de5

Please sign in to comment.