This is due to this issue.
We have a linker in Angular 1.6, which I port to Angular2 in a project using the Angular CLI. In Angular 1.6, it was easy to have an image next to your controller and its CSS, and then easily reference it along the path relative to the component catalog. For instance:
-components
--my-component
---my-component.controller.js
---my-component.css
---my-image.jpg
In my-component.css:
background-image: url(my-image.jpg);
According to the stated question, this is not possible with the Angular CLI. They recommend moving the image to the resource folder. Not an ideal solution, but everything is in order. Of course, if I split this component into my own node_module and import from there, Angular will be smart enough to allow paths relative to node_module, right? So far they’re out of luck.
So, how do we expect to use node_modules containing images specific to this module? Now it’s obvious for us to add a postinstall script that copies the image from the module to the project’s dependent resources folder, but this seems hacked and requires us to assume that they have a certain resource folder setting.
In short:
- Is there any way to refer to images that are in the component folder relative to this folder?
- If not, is there a way to refer to images that are located in module_node relative to node_module?
- If not, what is the best way to configure and maintain the module in conjunction with its images? Is postinstall the best idea for the job?
This one breaks my brain, and this is the first time I really wondered about Angular2 and the CLI. Thanks in advance!