Angular 6 Library assets not included in lib after build

孤者浪人 提交于 2021-02-09 09:37:16

问题


I have recently created an Angular library (ng new library) and had an issue after building it with the ng build --prod. My assets folder did not get copied to the dist folder and I can no longer reference my file. When I tried including the assets script in my angular.json I got an error - Schema validation failed with the following errors:

Data path "" should NOT have additional properties(assets).

Is there a way of including assets in an Angular library? Please help


回答1:


I had the same issue with Angular CLI 6.1.3. Change your assets part in your angular.json file :

"assets": [
  "src/favicon.ico",
  "src/web.config",
  "src/assets"
],

It works even if you don't have a web.config file.




回答2:


Now, ng-packagr released a new version that allows you to include the assets along with the build files:

You can copy these assets by using the assets option.

{
  "ngPackage": {
    "assets": [
      "CHANGELOG.md",
      "./styles/**/*.theme.scss"
    ],
    "lib": {
      ...
    }
  }
}

More information here: https://github.com/ng-packagr/ng-packagr/blob/master/docs/copy-assets.md



来源:https://stackoverflow.com/questions/52289213/angular-6-library-assets-not-included-in-lib-after-build

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!