# Publishable and Buildable Nx Libraries
```
=== notes ===
Buildable
Import path -
Not there yet, but will look to do in future
Link to incremental building doc
Publishable
Library to Publish to NPM
Ng-packagr in Angular
Adds node builder in React (check to confirm)
There’s a third, probably web
```
The `--buildable` and `--publishable` options are available on the Nx library generation schematics for the following plugins:
- Angular
- React
- NestJs
- Node
This document will look to explain the motivations for why you would use either the `--buildable` or `--publishable` option, as well as the mechanics of how they adjust the result when you add them to your schematic.
## Publishable libraries
You might want to use the `--publishable` option when generating a new Nx library, if your intention is to distribute it outside the monorepo. One typical scenarios might be that you use Nx to develop your organizations UI design system component library (maybe using its [Storybook integration](https://nx.dev/latest/plugins/storybook/overview)), which should be available also to your organizations' apps that are not hosted within the same monorepo.
A normal Nx library - let's call it "workspace library" - is not made for building or publishing. It rather just includes common lint and test targets in the `angular.json` or `workspace.json`. These libraries are directly referenced from one of the monorepo's applications and built together with them.
The `--publishable` flag does not enable automatic publishing. It rather adds to your Nx workspace library a `builder` target that **compiles** and **bundles** your app, ready to be published to some registry (e.g. [npm](https://npmjs.com)). By having that builder, you can invoke the build like `nx build mylib` which will then produce an optimized bundle in the `dist/mylib` folder. Nx [also analyzes](https://nx.dev/latest/angular/plugins/angular/builders/package#updatebuildableprojectdepsinpackagejson) the library's dependencies and automatically compiles the dependencies in the resulting `package.json` file.
One particularity when generating a library with `--publishable` is that it requires you to also provide the `--importPath`. That latter one is the actual scope of your distributable package, e.g. `@myorg/mylib`. It obviously needs to be a [valid npm package name](https://docs.npmjs.com/files/package.json#name).
To publish the library, say to npm, you can simply use `npm publish` in the according `dist` folder. Obviously setting up some automated script in Nx's `tools` folder might come in handy.
For more details on the mechanics, remember that Nx is an open source project, so you can see the actual impact of the schematic by looking at the source code (the best starting point is probably `packages/<framework>/src/schematics/library/library.ts`).
## Buildable libraries
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](https://nx.dev/latest/angular/guides/ci/incremental-builds) capabilities.
For more details on the mechanics, remember that Nx is an open source project, so you can see the actual impact of the schematic by looking at the source code (the best starting point is probably `packages/<framework>/src/schematics/library/library.ts`).