I've been moving chunks of shared code into a library that we can pull into our other projects, and part of that includes some core styles.
I have the library itself working, eventually (griping about documentation for all of this is a whole other topic), with a couple of the basic components. FYI, mostly set up using this as a guide.
However, I've just pulled in some more complex ones, and with it a couple of scss files that we want to use across projects as well as within the library components themselves (e.g. brand colouring, etc.).
I have my tsconfig.json
set up per the above guide so that all my components can import with import { x } from '@my-lib/core/src/lib/y';
.
I also found all the information eventually so that my styles are added to the output as assets so that our consuming projects have access to these; ng-package.json:
...
"assets: [
"./assets"
]
...
(Note: styles/fonts found in assets/styles
and assets/fonts
respectively).
On to the problems.
How am I supposed to reference these? Typically in our basic Angular projects its a simple @import 'src/styles/x';
kind of affair.
Making use of the path aliasing that I so enjoy with the components doesn't work, e.g. import '@my-lib/core/assets/styles/x';
.
Using a relative path does.. sort of. e.g. import '../../../assets/styles/x';
Note: One of the shared styles is for typography, and it has src: url(../fonts/xyz.eot
);` type usages (relative pathing).
At this point it gets further in the compilation process than the @my-lib
import, but throws up warnings to the effect:
WARNING: postcss-url: C:\.....\projects\core\src\lib\my-module\components\my-component\my-component.component.scss:36:3: Can't read file 'C:\.....\projects\core\src\lib\my-module\components\fonts\xyz', ignoring
The path suggests it's running the typography file in a literal sense, the ..\fonts
url is relative from the point of import (component) rather than its base file location within assets.
How do I get all this properly hooked up and why has no one managed to write basic guides for these things already?
Going to have to start my own 'idiots guide' blog just to dumb down instructions for others like myself...