|
| 1 | +# Rslib Nx Plugin |
| 2 | + |
| 3 | +An Nx plugin that provides executors for building and developing with [Rslib](https://lib.rsbuild.dev/), a framework-agnostic library building solution. |
| 4 | + |
| 5 | +## Executors |
| 6 | + |
| 7 | +### Build (`rslib:build`) |
| 8 | + |
| 9 | +Builds your library using Rslib. |
| 10 | + |
| 11 | +**Options:** |
| 12 | +- `configFile` (string): Path to the rslib config file (default: `rslib.config.ts`) |
| 13 | +- `outputPath` (string): Output directory for build artifacts |
| 14 | +- `watch` (boolean): Enable watch mode (default: `false`) |
| 15 | +- `mode` (string): Build mode - `development` or `production` (default: `production`) |
| 16 | +- `verbose` (boolean): Enable verbose logging (default: `false`) |
| 17 | + |
| 18 | +**Example usage in `project.json`:** |
| 19 | + |
| 20 | +```json |
| 21 | +{ |
| 22 | + "targets": { |
| 23 | + "build": { |
| 24 | + "executor": "rslib:build", |
| 25 | + "options": { |
| 26 | + "configFile": "rslib.config.ts", |
| 27 | + "mode": "production" |
| 28 | + } |
| 29 | + } |
| 30 | + } |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +### Dev (`rslib:dev`) |
| 35 | + |
| 36 | +Runs Rslib in development mode with hot reloading. |
| 37 | + |
| 38 | +**Options:** |
| 39 | +- `configFile` (string): Path to the rslib config file (default: `rslib.config.ts`) |
| 40 | +- `port` (number): Port to serve on (default: `3001`) |
| 41 | +- `host` (string): Host to serve on (default: `localhost`) |
| 42 | +- `open` (boolean): Open browser after starting (default: `false`) |
| 43 | +- `mode` (string): Development mode - `watch` or `mf-dev` (default: `mf-dev`) |
| 44 | +- `verbose` (boolean): Enable verbose logging (default: `false`) |
| 45 | + |
| 46 | +**Example usage in `project.json`:** |
| 47 | + |
| 48 | +```json |
| 49 | +{ |
| 50 | + "targets": { |
| 51 | + "dev": { |
| 52 | + "executor": "rslib:dev", |
| 53 | + "options": { |
| 54 | + "port": 3001, |
| 55 | + "mode": "mf-dev", |
| 56 | + "open": true |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +### Echo (`rslib:echo`) |
| 64 | + |
| 65 | +Simple echo executor for testing the plugin. |
| 66 | + |
| 67 | +**Options:** |
| 68 | +- `message` (string): Message to echo (default: `"Hello from rslib executor!"`) |
| 69 | + |
| 70 | +## Usage |
| 71 | + |
| 72 | +To use this plugin in your Nx workspace: |
| 73 | + |
| 74 | +1. Install the required dependencies: |
| 75 | + ```bash |
| 76 | + npm install @rslib/core |
| 77 | + ``` |
| 78 | + |
| 79 | +2. Register the plugin in your `nx.json`: |
| 80 | + ```json |
| 81 | + { |
| 82 | + "plugins": ["tools/rslib-plugin"] |
| 83 | + } |
| 84 | + ``` |
| 85 | + |
| 86 | +3. Configure your project's `project.json` to use the rslib executors: |
| 87 | + ```json |
| 88 | + { |
| 89 | + "targets": { |
| 90 | + "build": { |
| 91 | + "executor": "rslib:build" |
| 92 | + }, |
| 93 | + "dev": { |
| 94 | + "executor": "rslib:dev" |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + ``` |
| 99 | + |
| 100 | +4. Create an `rslib.config.ts` file in your project root: |
| 101 | + ```typescript |
| 102 | + import { defineConfig } from '@rslib/core'; |
| 103 | + |
| 104 | + export default defineConfig({ |
| 105 | + lib: [ |
| 106 | + { |
| 107 | + format: 'esm', |
| 108 | + dts: true, |
| 109 | + }, |
| 110 | + { |
| 111 | + format: 'cjs', |
| 112 | + } |
| 113 | + ], |
| 114 | + }); |
| 115 | + ``` |
| 116 | + |
| 117 | +## Examples |
| 118 | + |
| 119 | +### Building a library |
| 120 | +```bash |
| 121 | +nx run my-lib:build |
| 122 | +``` |
| 123 | + |
| 124 | +### Running in development mode |
| 125 | +```bash |
| 126 | +nx run my-lib:dev |
| 127 | +``` |
| 128 | + |
| 129 | +### Building with custom config |
| 130 | +```bash |
| 131 | +nx run my-lib:build --configFile=custom.rslib.config.ts |
| 132 | +``` |
| 133 | + |
| 134 | +### Running in watch mode |
| 135 | +```bash |
| 136 | +nx run my-lib:dev --mode=watch |
| 137 | +``` |
| 138 | + |
| 139 | +## Module Federation Support |
| 140 | + |
| 141 | +This plugin supports Rslib's Module Federation capabilities. Use the `mf-dev` mode to run your federated modules: |
| 142 | + |
| 143 | +```json |
| 144 | +{ |
| 145 | + "targets": { |
| 146 | + "mf-dev": { |
| 147 | + "executor": "rslib:dev", |
| 148 | + "options": { |
| 149 | + "mode": "mf-dev", |
| 150 | + "port": 3001 |
| 151 | + } |
| 152 | + } |
| 153 | + } |
| 154 | +} |
| 155 | +``` |
| 156 | + |
| 157 | +## Requirements |
| 158 | + |
| 159 | +- Nx >= 21.0.0 |
| 160 | +- @rslib/core >= 0.5.0 |
| 161 | +- Node.js >= 18.0.0 |
0 commit comments