【发布时间】:2020-01-04 13:16:13
【问题描述】:
我正在构建一个包含自定义图标字体的库。但是,当我使用ng build <library-name> --prod 构建我的库时,资产文件夹不包含在构建中,这意味着使用生产构建时图标不会显示。
我尝试了多种解决方案,例如在 angular.json 中添加 assets 数组并将 assets 文件夹复制到创建的 dist 文件夹。
我使用的是 Angular 8,该库是使用 angular-cli 创建的。
我尝试以两种方式包含字体:
在其中一个样式文件中使用@import url( '../assets/icon_font.css' );,并在需要它的组件之一中将../assets/icon_font.css 添加到styleUrls。 (icon_font.css是包含图标字体的css文件)
这是我的库目录的布局:
- src
- lib
- assets
- icon_font.css
- font files
- component that requires icons
- style sheet that has @import icon_font.css
- other components and classes
我希望 assets/ 目录中的 .ttf 和其他字体文件在导出的 dist 文件夹中可用。
【问题讨论】:
-
angular.json中是否包含assets文件夹?
-
是的,我将它包含在
options下,但是现在它给了我Schema validation错误:Data path "" should NOT have additional properties(assets). -
Assets 文件夹应仅包含在 Angular 应用中的
angular.json项目中。对于图书馆,您将收到 @AivarasKriksciunas 的错误。您必须将其添加到目标库的ng-package.json项目文件夹下 -
您可以采取另一种方法:在库中包含图标,如显示此链接:netbasal.com/…
标签: angular angular-cli assets angular-library ng-packagr