[英]Managing shared styles and assets in Ngrx-nx Monorepo
我正在尝试在nrwl-nx monorepo中设置共享样式和资产(即字体),以便在库和应用程序中使用。
我想要的结果是拥有一个图书馆“主题”
用于其他库和应用程序。
对于1.和2.,我在这里找到了一个很好的答案: 如何在具有不同库共享变量的monorepo中管理SCSS样式表?
蒂姆·康索拉齐奥(Tim Consolazio)提出了一种很好的方法(并且受Nrwl启发)来处理跨monorepo的共享样式。 基本思想是在libs/theme/scss/src/lib/theme.scss
中有一个入口点scss,该入口点正在apps/myapp/src/styles.scss
。 一切正常。
我很难过的是,通过提供共享样式中使用的字体来libs/theme/scss/src/lib/fonts.scss
,例如,我有一个libs/theme/scss/src/lib/fonts.scss
,它从主题库。
项目结构是
- apps
- myapp
- src
- styles.scss (@import 'theme' from the lib)
- libs
- theme
- assets
- src
- lib
- fonts
- myfont.ttf
...
- scss
- src
- lib
- fonts.scss
- theme.scss
- variables.scss
...
目标是将资产包含在themes
库中。 我试图在angular.json
添加到architect.build.assets
数组中。 但是在引用字体样式表中的字体时,我无法找出要设置的正确路径:
@font-face {
font-family: 'My-Font';
src: url('./assets/fonts/myfont.eot');
src: url('./assets/fonts/myfont.eot?#iefix') format('embedded-opentype'),
url('./assets/fonts/myfont.woff2') format('woff2'),
url('./assets/fonts/myfont.woff') format('woff'),
url('./assets/fonts/myfont.ttf') format('truetype');
}
我想念什么?
因此,在经历了许多头痛之后,我做出了一个非常简单的解决方案,如本文中所建议的那样,并进行了一些细微的调整以使其正常工作。
项目结构:
- libs
- theme
- assets
- fonts
- myfont.ttf
...
关键是将共享资产的glob添加到angular.json
每个应用中,例如
projects.my-project-1.architect.build.options.assets
projects.my-project-2.architect.build.options.assets
{
"glob": "**/*",
"input": "libs/theme/assets/",
"output": "/assets/"
}
另外,我必须将scss中字体文件的导入路径更改为绝对路径:
@font-face {
font-family: 'My-Font';
src: url('/assets/fonts/myfont.eot');
src: url('/assets/fonts/myfont.eot?#iefix') format('embedded-opentype'),
url('/assets/fonts/myfont.woff2') format('woff2'),
url('/assets/fonts/myfont.woff') format('woff'),
url('/assets/fonts/myfont.ttf') format('truetype');
}
对我有用,但我很乐意了解更优雅的解决方案-特别是对于每个新应用程序都必须复制粘贴资产范围的问题困扰着我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.