Skip to content
rathkitPublic

About

Nx plugin for Rathkit Pack (rkp): inferred build, serve and watch tasks, executors and an init generator.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

@rathkit/nx-plugin

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.

Peer dependencies

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.

Install

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).

What it does

  • Inferred tasks (createNodes): a project with a rathkit.config.{mjs,js,cjs} next to its package.json or project.json gets build, serve and watch, with inputs, outputs, caching and dependsOn: ["^build"] set. See docs/spike-9.1.md for how the inputs are chosen.

  • Executors @rathkit/nx-plugin:build and @rathkit/nx-plugin:serve for targets written by hand in project.json.

  • Libraries: a project whose package.json has main, module, types or exports (and no index.html) builds in library mode: ES module (.mjs) and CommonJS (.cjs) files, declaration files when typescript and a tsconfig.json are found, packages left external, and a package.json in the output folder with main, module, types and exports written by rkp. The output folder is the package to publish (pnpm publish dist). The project's own package.json is never edited by a build. For the other projects of the workspace to consume the library, point its own fields at dist:

    { "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; build and watch are inferred, and the apps that use it get dependsOn: ["^build"].

Targets written by hand

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).

Develop

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).

Contributing

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.

License

Apache-2.0. See LICENSE and NOTICE.

About

Nx plugin for Rathkit Pack (rkp): inferred build, serve and watch tasks, executors and an init generator.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages