@anarchitects/nx-js
v0.1.0
Published
Anarchitects Nx JS plugin with enhanced secondary entry point support.
Readme
@anarchitects/nx-js
An Nx plugin that extends @nx/js with first-class secondary entry point generation for JavaScript and TypeScript libraries.
It provides a single generator that scaffolds the source files for a secondary entry point and automatically wires it into the library's build target — for all bundlers @nx/js supports, including libraries that rely on inferred targets.
Installation
Use nx add — the standard Nx way to adopt a plugin:
nx add @anarchitects/nx-jsOr install manually:
yarn add -D @anarchitects/nx-js
# or
npm install -D @anarchitects/nx-jsCompatibility: supports Nx >=21.6.4 <23.
Generators
secondary-entry-point
Adds a secondary export path to an existing library.
nx g @anarchitects/nx-js:secondary-entry-point --project=<project> --name=<segment>Required options
| Option | Description |
| --- | --- |
| --project | Name of the Nx library project to add the entry point to. |
| --name | Path segment for the new entry point (e.g. feature, data/access). |
Optional options
| Option | Default | Description |
| --- | --- | --- |
| --buildTarget | build | Name of the build target to update. |
| --skipFormat | false | Skip formatting generated files. |
What it does
The generator always runs these steps:
- Validates
--projectand--name. - Normalizes
--nameinto path-safe segments (e.g.Data/Access→data/access). - Creates source files in the library:
src/<segment>/index.tssrc/<segment>/lib/<leaf-segment>.ts
- Fails if
src/<segment>/index.tsalready exists. - Updates the build target configuration based on the bundler in use (see table below).
Bundler behavior
| Bundler | Executor | What is updated | Mutation |
| --- | --- | --- | --- |
| tsc | @nx/js:tsc | project.json | Appends to options.additionalEntryPoints[]; sets options.generateExportsField = true. |
| swc | @nx/js:swc | project.json | Appends to options.additionalEntryPoints[]; sets options.generateExportsField = true. |
| rollup | @nx/rollup:rollup | project.json | Appends to options.additionalEntryPoints[]; sets options.generateExportsField = true. |
| esbuild | @nx/esbuild:esbuild | project.json | Appends to options.additionalEntryPoints[]; sets options.generateExportsField = true. |
| vite | @nx/vite:build | vite.config.* | Adds "<segment>/index": "src/<segment>/index.ts" to build.lib.entry. Converts entry from a string to an object if needed. |
Inferred targets
For libraries that use Project Crystal inference (no explicit build target in project.json), the generator detects the bundler by checking for its config file:
rollup.config.js|ts|mjs|mts|cjs→ treated as rollup; entry points are written intoproject.json.vite.config.ts|mts|js|mjs|cjs→ treated as vite; the config file is updated directly.
Additional notes
additionalEntryPointsis deduplicated and sorted on every update.generateExportsFieldis forced totrueso Nx emits secondary exports in the builtpackage.json.- The generator never mutates the source
package.jsonexports directly. - Unknown executors are skipped with a warning so you can configure entry points manually.
Example
nx g @anarchitects/nx-js:secondary-entry-point --project=my-lib --name=featureCreated files:
libs/my-lib/src/feature/index.ts
libs/my-lib/src/feature/lib/feature.tsFor tsc, swc, rollup, esbuild — project.json build options after the run:
{
"options": {
"additionalEntryPoints": ["libs/my-lib/src/feature/index.ts"],
"generateExportsField": true
}
}For vite — vite.config.* after the run:
entry: {
index: 'src/index.ts',
'feature/index': 'src/feature/index.ts',
}Development
Build:
yarn nx build nx-jsTest:
yarn nx test nx-jsLint:
yarn nx lint nx-jsLicense
This project is licensed under the Apache License 2.0.
