Skip to content

Module path prefix is not used to resolve styleUrl or templateUrl with AoT #5056

@PierreDuc

Description

@PierreDuc

OS?

Windows 10

Versions.

@angular/cli: 1.0.0-rc.0
node: 7.5.0
os: win32 x64
@angular/common: 4.0.0-rc.1
@angular/compiler: 4.0.0-rc.1
@angular/core: 4.0.0-rc.1
@angular/flex-layout: 2.0.0-rc.1
@angular/forms: 4.0.0-rc.1
@angular/http: 4.0.0-rc.1
@angular/platform-browser: 4.0.0-rc.1
@angular/platform-browser-dynamic: 4.0.0-rc.1
@angular/router: 4.0.0-rc.1
@angular/cli: 1.0.0-rc.0
@angular/compiler-cli: 4.0.0-rc.1

Repro steps.

Due to reasons we have our style sheets in a separate root folder. A couple versions ago we were able to load the styling using:

@Component({
    //...
    styleUrls: [
        "@style_folder/components/component/name.component.scss"
    ]
})

Then something changed a couple versions ago and module paths were resolved as relative paths, so ./ was appended to the url. This is done in the loader-utils package. I've read there that I could append a ~ to the url, to convert it to a module request. (~@style_folder/bla/bla) This worked splendidly (with the minor downside that I could no longer navigate to it using my IDE).

We are in the process of making our application AoT compatible, and to our big surprise, the ~ trick doesn't work there, because AoT thinks it's a relative path no matter what.

We would prefer it to not have all relative paths inside our styleUrls (../../../ horror). Better would be that both JIT and AoT look at the paths defined in tsconfig.json (like it was before I believe) and look there for a definition, and only after that assume it's a relative path if there is no match.

Metadata

Metadata

Assignees

Labels

P1Impacts a large percentage of users; if a workaround exists it is partial or overly painfultype: bug/fix

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions