如何解决复制资产作为Angular 9 Library构建的一部分
我正在阅读:https://angular.io/guide/creating-libraries,其中指出:
从ng-packagr工具的9.x版本开始,您可以配置该工具以在构建过程中自动将资产复制到库包中。当您的图书馆需要发布可选的主题文件,Sass mixins或文档(如变更日志)时,可以使用此功能。
链接将您带到这里:https://github.com/ng-packagr/ng-packagr/blob/master/docs/copy-assets.md
对我来说,这是如此模棱两可。它不会告诉您该选项的放置位置,但是从说明中看,它似乎是选项的一部分:
"options": {
"tsConfig": "projects/situ-angular-components/tsconfig.lib.json","project": "projects/situ-angular-components/ng-package.json","assets": [
"CHANGELOG.md","./styles/**/*.theme.scss"
]
},
如果这样做,我会收到此错误:
架构验证失败,出现以下错误: 数据路径“”不应具有其他属性(资产)。
我完整的angular.json看起来像这样:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json","version": 1,"newProjectRoot": "projects","projects": {
"situ-angular-components": {
"projectType": "library","root": "projects/situ-angular-components","sourceRoot": "projects/situ-angular-components/src","prefix": "situ","schematics": {
"@schematics/angular:component": {
"styleext": "scss"
}
},"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build","options": {
"tsConfig": "projects/situ-angular-components/tsconfig.lib.json","assets": [
"CHANGELOG.md","./styles/**/*.theme.scss"
]
},"configurations": {
"production": {
"tsConfig": "projects/situ-angular-components/tsconfig.lib.prod.json"
}
}
},"test": {
"builder": "@angular-devkit/build-angular:karma","options": {
"main": "projects/situ-angular-components/src/test.ts","tsConfig": "projects/situ-angular-components/tsconfig.spec.json","karmaConfig": "projects/situ-angular-components/karma.conf.js"
}
},"lint": {
"builder": "@angular-devkit/build-angular:tslint","options": {
"tsConfig": [
"projects/situ-angular-components/tsconfig.lib.json","projects/situ-angular-components/tsconfig.spec.json"
],"exclude": ["**/node_modules/**"]
}
}
}
}
},"cli": {
"analytics": "8db81fee-b0bd-41b0-a453-27aa6be6cc88"
},"defaultProject": "situ-angular-components"
}
如果将资产移至以下级别,则不会出错,但是不会复制任何资产:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json","project": "projects/situ-angular-components/ng-package.json"
},"assets": [
"CHANGELOG.md","./styles/**/*.theme.scss"
],"defaultProject": "situ-angular-components"
}
有人知道我在做什么错吗?
解决方法
我知道了。 您只需要编辑 ng-package.json 文件并添加资产:
"assets": [
".npmrc"
],
这将复制您的文件。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。