[英]How to import SCSS library with assets in Angular application?
I have a SCSS library packaged as npm module, it has the following structure: 我有一个打包为npm模块的SCSS库,它具有以下结构:
./index.scss
./partials/_foo.scss
./assets/foo.svg
And the _foo.scss
contains a relative path to the image: _foo.scss
包含图像的相对路径:
.foo {
background-image: url('../assets/foo.svg');
}
When I import the index.scss
file in my Angular application's style.scss
, I'm getting a compilation error, because the compiler can't resolve the path to the image for some reason, however, the path is correct (relative to the original SCSS-file). 当我在Angular应用程序的
style.scss
导入index.scss
文件时,出现编译错误,因为编译器由于某种原因无法解析图像的路径,但是,该路径是正确的(相对于原始SCSS文件)。
I know I can use a variable to specify the base path in the library and then override it in the project where I import it, but I rather won't do it this way, because it adds more clutter to the library itself and requires the end-developer to override the variable in order to use the library. 我知道我可以使用变量在库中指定基本路径,然后在导入它的项目中覆盖它,但是我宁愿不这样做,因为它会给库本身增加更多混乱,并且需要最终开发人员将覆盖该变量以使用该库。
如果您使用url('~nameofnodemodule/assets/foo.svg')
webpack应该能够找到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.