Skip to content

Commit 0b0c5da

Browse files
ScriptedAlchemycursoragentclaudegithub-advanced-security[bot]
authored
feat: implement rslib with TypeScript declaration generation (#3883)
Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: Claude <[email protected]> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent bb953a6 commit 0b0c5da

34 files changed

+1803
-63
lines changed

tools/rslib-plugin/README.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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

tools/rslib-plugin/dist/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@workspace/rslib-plugin",
3+
"version": "0.1.0",
4+
"description": "Nx plugin for Rslib",
5+
"main": "./src/index.js",
6+
"generators": "./generators.json",
7+
"executors": "./executors.json",
8+
"type": "commonjs",
9+
"exports": {
10+
"./package.json": "./package.json",
11+
"./generators.json": "./generators.json",
12+
"./executors.json": "./executors.json",
13+
".": "./src/index.js"
14+
},
15+
"dependencies": {
16+
"@nx/devkit": "^21.0.0",
17+
"@rslib/core": "^0.10.4"
18+
},
19+
"devDependencies": {
20+
"@types/node": "^20.0.0"
21+
},
22+
"peerDependencies": {
23+
"@rslib/core": ">=0.10.0"
24+
},
25+
"types": "./tools/rslib-plugin/src/index.d.ts"
26+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { ExecutorContext } from '@nx/devkit';
2+
export interface RslibBuildExecutorOptions {
3+
configFile?: string;
4+
outputPath?: string;
5+
watch?: boolean;
6+
mode?: 'development' | 'production';
7+
verbose?: boolean;
8+
main?: string;
9+
additionalEntryPoints?: string[];
10+
external?: string[];
11+
format?: ('cjs' | 'esm' | 'umd' | 'iife')[];
12+
tsConfig?: string;
13+
assets?: (string | {
14+
glob: string;
15+
input: string;
16+
output: string;
17+
ignore?: string[];
18+
})[];
19+
project?: string;
20+
}
21+
export default function rslibBuildExecutor(options: RslibBuildExecutorOptions, context: ExecutorContext): Promise<{
22+
success: boolean;
23+
}>;

0 commit comments

Comments
 (0)