An Nx plugin for Rathkit Pack (rkp), a JavaScript and TypeScript bundler written in Rust with zero dependencies.
Status: beta. Targets and options can change between 0.x releases. On npm under the next tag.
nx and @nx/devkit are peer dependencies, because that is what an Nx plugin is: it runs inside the Nx of your workspace and uses its API,
so it must not bring a copy of its own. So is @rathkit/pack, the package that gives the rkp program. @rathkit/nx-plugin itself has no
dependencies (pnpm check:zero-deps enforces it).
| Peer | Versions | Why |
|---|---|---|
nx |
23 and 24 (the current and the previous major) | the plugin API, the task runner |
@nx/devkit |
the same as nx |
the generators |
@rathkit/pack |
any (0.x is beta) | the rkp program the executors run |
@rathkit/pack is an optional peer, so a package manager does not install it by itself (left to itself it would pick the latest tag, which
is not a usable version of Pack). nx add adds @rathkit/pack@next for you; by hand, name it as below.
nx add @rathkit/nx-plugin
or by hand: pnpm add -D @rathkit/nx-plugin@next @rathkit/pack@next and add "@rathkit/nx-plugin" to plugins in nx.json (at the root of a
pnpm workspace, add -w).
-
Inferred tasks (
createNodes): a project with arathkit.config.{mjs,js,cjs}next to itspackage.jsonorproject.jsongetsbuild,serveandwatch, with inputs, outputs, caching anddependsOn: ["^build"]set. See docs/spike-9.1.md for how the inputs are chosen. -
Executors
@rathkit/nx-plugin:buildand@rathkit/nx-plugin:servefor targets written by hand inproject.json. -
Libraries: a project whose
package.jsonhasmain,module,typesorexports(and noindex.html) builds in library mode: ES module (.mjs) and CommonJS (.cjs) files, declaration files whentypescriptand atsconfig.jsonare found, packages left external, and apackage.jsonin the output folder withmain,module,typesandexportswritten by rkp. The output folder is the package to publish (pnpm publish dist). The project's ownpackage.jsonis never edited by a build. For the other projects of the workspace to consume the library, point its own fields atdist:{ "files": ["dist"], "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.mjs", "require": "./dist/index.cjs" } } }A library is not served;
buildandwatchare inferred, and the apps that use it getdependsOn: ["^build"].
Without the plugin (or to override it), use the executors in a project.json. Options are in src/executors/*/schema.json; args passes any other
rkp flag as written. nx.json can set the shared parts once:
{
"targetDefaults": {
"@rathkit/nx-plugin:build": {
"cache": true,
"dependsOn": ["^build"],
"inputs": ["default", "^default", "!{projectRoot}/dist/**/*", { "externalDependencies": ["@rathkit/pack"] }],
"outputs": ["{options.outputPath}"]
}
}
}{
"name": "web",
"targets": {
"build": { "executor": "@rathkit/nx-plugin:build", "options": { "outputPath": "{projectRoot}/dist", "minify": true } },
"serve": { "executor": "@rathkit/nx-plugin:serve", "options": { "port": 4200 } }
}
}The program is found from the rkpBin option, then the RATHKIT_PACK_BIN variable, then the installed @rathkit/pack, then rkp on PATH.
outputPath is deleted before a build ("clean": false keeps it).
Node and pnpm versions are in package.json (engines, packageManager) and .node-version. Use pnpm, never npm or yarn.
pnpm install
pnpm check # zero-deps check and the tests
The tests build real Nx workspaces in node_modules/.cache/rathkit-nx-test (override with RATHKIT_NX_TEST_DIR), install nx and @nx/devkit
from the network, and need an rkp program: set RATHKIT_PACK_BIN to a release build of rathkit/pack
(cargo build --release); without it they are skipped. RATHKIT_NX_VERSION picks the Nx version (default 24.0.6); RATHKIT_PACK_SPEC picks how @rathkit/pack is
installed into the workspaces (default: the npm/pack folder of the checkout).
Read CONTRIBUTING.md first: it covers the issue-first rule, signed commits with a sign-off (DCO), the AI policy, the code of conduct, governance and members.