×
  • 建立和发布Angular库(v10)的最佳方法

  • 03 –管理Angular库依赖关系

    课程清单

    在本课程中,我们将了解如何设置或管理Angular库依赖,这意味着从属软件包将安装在任何已安装的angular项目中。
    让我们考虑一下我们当前的新闻API服务,因此在API请求待处理之前,我们将显示一个加载程序,并且该加载程序将 ngx-spinner

    安装Angular库依赖

    要安装依赖项,请转到库文件夹,然后在该文件夹中运行

    重击
    
    npm install ngx-spinner --save
    

    This will create a node module folder in your library folder and package.json will get updated.
    Also if you have some pre-installed packages in your angular application workspace we can just add that package in the package.json file.

    news-twentyfour / package.json
    
    {
      "name": "news-twentyfour",
      "version": "0.0.1",
      "peerDependencies": {
        "@angular/common": "^10.1.1",
        "@angular/core": "^10.1.1"
      },
      "dependencies": {
        "angular-epic-spinners": "^2.0.0",
        "ngx-spinner": "^10.0.1",
        "lodash": "^4.17.4", // custom added
        "tslib": "^2.0.0"
      }
    }
    

    因此,每当用户安装库时,都会安装已定义的依赖项。

    设置外部软件包的样式和脚本

    Some of the plugin that required the styles to be imported during build through angular.json we can also do that for the library.

    app / angular.json
    
    "news-twentyfour": {
      "projectType": "library",
      "root": "projects/news-twentyfour",
      "sourceRoot": "projects/news-twentyfour/src",
      "prefix": "lib",
      "architect": {
       "build": {
         "builder": "@angular-devkit/build-angular:ng-packagr",
         "options": {
           "tsConfig": "projects/news-twentyfour/tsconfig.lib.json",
           "project": "projects/news-twentyfour/ng-package.json",
           "styles": [
             "node_modules/primeicons/primeicons.css", // package styles
             "projects/news-twentyfour/styles.css" // custom styles
           ]
         }
         // ...
       }
      }
    }
    
    Angular库依赖
    .
    .
  • 启用通知    不用了,谢谢