@@ -25,42 +25,51 @@ export function createCssResourcePlugin(url: CssUrl, cache?: LoadResultCache): P
2525 name : 'angular-css-resource' ,
2626 setup ( build : PluginBuild ) : void {
2727 build . onResolve ( { filter : / .* / } , async args => {
28+ const { importer, path, kind, resolveDir, namespace, pluginData = { } } = args ;
29+
2830 // Only attempt to resolve url tokens which only exist inside CSS.
2931 // Also, skip this plugin if already attempting to resolve the url-token.
30- if ( args . kind !== 'url-token' || args . pluginData ?. [ CSS_RESOURCE_RESOLUTION ] ) {
32+ if ( kind !== 'url-token' || pluginData [ CSS_RESOURCE_RESOLUTION ] ) {
3133 return null ;
3234 }
3335
36+ let [ containingDir , resourceUrl ] = path . split ( '||file:' , 2 ) ;
37+ if ( resourceUrl === undefined ) {
38+ // This can happen due to early exit checks in rebasing-importer
39+ // logic such as when the url is an external URL.
40+ resourceUrl = containingDir ;
41+ containingDir = '' ;
42+ }
43+
3444 // If root-relative, absolute or protocol relative url, mark as external to leave the
3545 // path/URL in place.
36- if ( url !== CssUrl . inline || / ^ ( (?: \w + : ) ? \/ \/ | d a t a : | c h r o m e : | # | \/ ) / . test ( args . path ) ) {
46+ if ( url !== CssUrl . inline || / ^ ( (?: \w + : ) ? \/ \/ | d a t a : | c h r o m e : | # | \/ ) / . test ( resourceUrl ) ) {
3747 return {
38- path : args . path ,
48+ path : resourceUrl ,
3949 external : true ,
4050 } ;
4151 }
4252
43- const { importer, kind, resolveDir, namespace, pluginData = { } } = args ;
4453 pluginData [ CSS_RESOURCE_RESOLUTION ] = true ;
4554
46- const result = await build . resolve ( args . path , {
55+ const result = await build . resolve ( resourceUrl , {
4756 importer,
4857 kind,
4958 namespace,
5059 pluginData,
51- resolveDir,
60+ resolveDir : join ( resolveDir , containingDir ) ,
5261 } ) ;
5362
5463 if ( result . errors . length ) {
5564 const error = result . errors [ 0 ] ;
56- if ( args . path [ 0 ] === '~' ) {
65+ if ( resourceUrl [ 0 ] === '~' ) {
5766 error . notes = [
5867 {
5968 location : null ,
6069 text : 'You can remove the tilde and use a relative path to reference it, which should remove this error.' ,
6170 } ,
6271 ] ;
63- } else if ( args . path [ 0 ] === '^' ) {
72+ } else if ( resourceUrl [ 0 ] === '^' ) {
6473 error . notes = [
6574 {
6675 location : null ,
0 commit comments