0%

nx-library-types

Nx Library Types by functionality

Feature library

此类library主要负责和业务相关的组件和页面等等。

UI library

此类Library主要是负责和UI相关的功能。

Data access library

此类library主要负责和数据相关的功能,比如和后端API交互,数据处理等。

Utility library

此类library主要负责工具和辅助功能,比如一些通用的函数,服务等。

Nx library types by buildable and publishable

Workspace library(Normal library)

Create without any options, it’s a normal library.

1
nx g @nx/angular:lib libName
  • No ng-packagr file generated.
  • No package.json file generated .
  • No targets/build section in project.json file.

This type of libraries is intended to be used within the monorepo. It was imported by apps or other libraries in the same monorepo. It can’t be builded or published independently.

Buildable library

Create by adding buildable option.

1
nx g @nx/angular:lib libName --buildable
  • Add ng-packagr file to root of the library.
  • Add package.json file to root of the library.
  • name property in package.json is the libName.
  • Add targets/build section in project.json file.
  • Executor of build is: "executor": "@nx/angular:ng-packagr-lite"

Buildable libraries are similar to “publishable libraries” described above. Their scope however is not to distribute or publish them to some external registry. Thus they might not be optimized for bundling and distribution.

Buildable libraries are mostly used for producing some pre-compiled output that can be directly referenced from an Nx workspace application without the need to again compile it. A typical scenario is to leverage Nx’s incremental building capabilities.

Publishable library

Create by adding publishable and importPath option. importPath is the path that the library will be imported from, will be used as name of the package.

1
nx g @nx/angular:lib libName --publishable --importPath=@myorg/libName
  • Add ng-packagr file to root of the library.
  • Add package.json file to root of the library.
  • name property in package.json is the importPath.
  • Add targets/build section in project.json file.
  • Executor of build is: "executor": "@nx/angular:package"

Publishable libraries is intended to be published outside of the monorepo, and can be imported by other projects.

References