fix(ivy): check the presence of .css resource for styleUrls (#28770)
Prior to this change, Ivy and VE CSS resource resolution was different: in addition to specified styleUrl (with .scss, .less and .styl extensions), VE also makes an attempt to resolve resource with .css extension. This change introduces similar logic for Ivy to make sure Ivy behavior is backwards compatible. PR Close #28770
This commit is contained in:

committed by
Igor Minar

parent
be121bba85
commit
72d043f669
@ -11,6 +11,8 @@ import * as ts from 'typescript';
|
||||
import {CompilerHost} from '../transformers/api';
|
||||
import {ResourceLoader} from './annotations/src/api';
|
||||
|
||||
const CSS_PREPROCESSOR_EXT = /(\.scss|\.less|\.styl)$/;
|
||||
|
||||
/**
|
||||
* `ResourceLoader` which delegates to a `CompilerHost` resource loading method.
|
||||
*/
|
||||
@ -123,6 +125,16 @@ export class HostResourceLoader implements ResourceLoader {
|
||||
for (const candidate of candidateLocations) {
|
||||
if (fs.existsSync(candidate)) {
|
||||
return candidate;
|
||||
} else if (CSS_PREPROCESSOR_EXT.test(candidate)) {
|
||||
/**
|
||||
* If the user specified styleUrl points to *.scss, but the Sass compiler was run before
|
||||
* Angular, then the resource may have been generated as *.css. Simply try the resolution
|
||||
* again.
|
||||
*/
|
||||
const cssFallbackUrl = candidate.replace(CSS_PREPROCESSOR_EXT, '.css');
|
||||
if (fs.existsSync(cssFallbackUrl)) {
|
||||
return cssFallbackUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user