[英]Angular shared assets within multiple applications
I am working on multiple small apps, which will share common and shared modules, and assets.我正在开发多个小型应用程序,它们将共享通用和共享模块以及资产。
The part about how to create project structure was answered here: https://stackoverflow.com/a/61254557/1351452关于如何创建项目结构的部分在这里得到了回答: https://stackoverflow.com/a/61254557/1351452
My project folders structure is as follow: -root --projects ---app1 ---app2 ---library我的项目文件夹结构如下:-root --projects ---app1 ---app2 ---library
Put assets in root folder: root/assets/
将资产放在根文件夹中: root/assets/
and change the path to assets in angular.json
并更改angular.json
中资产的路径
{
...
"projects": {
"app1": {
"projectType": "application",
...
"architect": {
"build": {
...
"options": {
...
"assets": [
// change this
// "projects/app1/src/assets",
"assets",
],
}
}
}
},
"app2": {
"projectType": "application",
...
"architect": {
"build": {
...
"options": {
...
"assets": [
// change this
// "projects/app2/src/assets",
"assets",
],
}
}
}
}
}
}
I tried to achieve pretty much the same thing.我试图实现几乎相同的目标。 However, I do not build my library.但是,我不建立我的图书馆。 I just link to the library.module and use the components like that.我只是链接到 library.module 并使用这样的组件。
And now, for the shared assets:现在,对于共享资产:
In angular.json
, I added the library's.scss to the app's build options, so it looked like this:在angular.json
中,我将 library's.scss 添加到应用程序的构建选项中,所以它看起来像这样:
"styles": [
"projects/library/src/styles.scss",
"projects/app1/src/styles.scss"
],
I did not add the library's asset folder to the project's asset section because according to CLI "tHaT DoEsN't WoRk" ( The assets asset path must start with the project source root.
)我没有将库的资产文件夹添加到项目的资产部分,因为根据 CLI “tHaT DoEsN't WoRk”( The assets asset path must start with the project source root.
)
Now what?.怎么办?。 I realised the font files I declared in my library's style.scss got copied: This lead me to this thought, What happens?我意识到我在库的 style.scss 中声明的字体文件被复制了:这让我想到,会发生什么? if I also reference my assets in that file?如果我还在该文件中引用我的资产? So I put this in the project/library/src/styles.scss
:所以我把它放在project/library/src/styles.scss
:
// fixes for library assets (they're not included if not listed here)
.its-2020-and-this-still-doesnt-work-out-of-the-box {
background-image: url('assets/my-shared-logo.svg');
}
Then I was able to reference these assets from within my library's components like this:然后我可以从我的库组件中引用这些资产,如下所示:
<!-- library assets must be loaded from root level -->
<img src="my-shared-logo.svg" alt="" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.