Skip to content

Commit 18a8584

Browse files
committed
fix(@angular/build): ensure SVG template URLs are considered templates with external stylesheets
When using the development server with the application builder (default for new projects), the external stylesheet functionality for component style hot replacement was incorrectly considering SVG files as stylesheet resources. This resulted in a build error when using SVG files as a template source. The file extension based checks have now been improved to account for this usage. (cherry picked from commit 2aa25a7)
1 parent 3aca1e6 commit 18a8584

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/angular/build/src/tools/angular/angular-host.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,9 @@ export function createAngularCompilerHost(
208208
host.resourceNameToFileName = function (resourceName, containingFile) {
209209
const resolvedPath = nodePath.join(nodePath.dirname(containingFile), resourceName);
210210

211-
// All resource names that have HTML file extensions are assumed to be templates
212-
if (resourceName.endsWith('.html') || !hostOptions.externalStylesheets) {
211+
// All resource names that have template file extensions are assumed to be templates
212+
// TODO: Update compiler to provide the resource type to avoid extension matching here.
213+
if (!hostOptions.externalStylesheets || hasTemplateExtension(resolvedPath)) {
213214
return resolvedPath;
214215
}
215216

@@ -248,3 +249,16 @@ export function createAngularCompilerHost(
248249

249250
return host;
250251
}
252+
253+
function hasTemplateExtension(file: string): boolean {
254+
const extension = nodePath.extname(file).toLowerCase();
255+
256+
switch (extension) {
257+
case '.htm':
258+
case '.html':
259+
case '.svg':
260+
return true;
261+
}
262+
263+
return false;
264+
}

0 commit comments

Comments
 (0)