Skip to content

Commit c7dd686

Browse files
Merge remote-tracking branch 'origin/main' into cursor/build-system-turborepo-14f4
# Conflicts: # apps/shared-tree-shaking/no-server/host/project.json # apps/shared-tree-shaking/with-server/host/project.json # packages/bridge/bridge-react/project.json # packages/core/project.json # packages/data-prefetch/project.json # packages/dts-plugin/project.json # packages/enhanced/project.json # packages/enhanced/tsdown.config.ts # packages/error-codes/project.json # packages/managers/project.json # packages/manifest/project.json # packages/metro-core/project.json # packages/metro-plugin-rnc-cli/project.json # packages/modernjs-v3/project.json # packages/modernjs/project.json # packages/native-federation-tests/project.json # packages/native-federation-typescript/project.json # packages/nextjs-mf/project.json # packages/node/project.json # packages/rsbuild-plugin/project.json # packages/rspack/project.json # packages/runtime-tools/project.json # packages/sdk/project.json # packages/storybook-addon/project.json # packages/third-party-dts-extractor/project.json # packages/typescript/project.json # packages/utilities/project.json # packages/webpack-bundler-runtime/project.json # pnpm-lock.yaml # project.json # tools/rslib-plugin/dist/package.json # tools/rslib-plugin/dist/src/executors/build/executor.d.ts # tools/rslib-plugin/dist/src/executors/build/executor.js # tools/rslib-plugin/dist/src/executors/build/executor.js.map # tools/rslib-plugin/dist/src/executors/dev/executor.d.ts # tools/rslib-plugin/dist/src/executors/dev/executor.js # tools/rslib-plugin/dist/src/executors/dev/executor.js.map # tools/rslib-plugin/dist/src/executors/echo/executor.d.ts # tools/rslib-plugin/dist/src/executors/echo/executor.js # tools/rslib-plugin/dist/src/executors/echo/executor.js.map # tools/rslib-plugin/dist/src/index.d.ts # tools/rslib-plugin/dist/src/index.js # tools/rslib-plugin/project.json
2 parents fa538aa + 941eabb commit c7dd686

File tree

4 files changed

+211
-31
lines changed

4 files changed

+211
-31
lines changed

packages/enhanced/tsdown.config.ts

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,13 @@ export default defineConfig([
44
{
55
name: 'enhanced-build',
66
cwd: import.meta.dirname,
7-
entry: {
8-
index: 'src/index.ts',
9-
webpack: 'src/webpack.ts',
10-
rspack: 'src/rspack.ts',
11-
runtime: 'src/runtime.ts',
12-
prefetch: 'src/prefetch.ts',
13-
'lib/container/AsyncBoundaryPlugin':
14-
'src/lib/container/AsyncBoundaryPlugin.ts',
15-
'lib/container/ContainerPlugin': 'src/lib/container/ContainerPlugin.ts',
16-
'lib/container/ContainerReferencePlugin':
17-
'src/lib/container/ContainerReferencePlugin.ts',
18-
'lib/container/HoistContainerReferencesPlugin':
19-
'src/lib/container/HoistContainerReferencesPlugin.ts',
20-
'lib/container/ModuleFederationPlugin':
21-
'src/lib/container/ModuleFederationPlugin.ts',
22-
'lib/container/runtime/FederationModulesPlugin':
23-
'src/lib/container/runtime/FederationModulesPlugin.ts',
24-
'lib/container/runtime/FederationRuntimePlugin':
25-
'src/lib/container/runtime/FederationRuntimePlugin.ts',
26-
'lib/sharing/ConsumeSharedPlugin':
27-
'src/lib/sharing/ConsumeSharedPlugin.ts',
28-
'lib/sharing/ProvideSharedPlugin':
29-
'src/lib/sharing/ProvideSharedPlugin.ts',
30-
'lib/sharing/SharePlugin': 'src/lib/sharing/SharePlugin.ts',
31-
'lib/sharing/tree-shaking/TreeShakingSharedPlugin':
32-
'src/lib/sharing/tree-shaking/TreeShakingSharedPlugin.ts',
33-
},
7+
// Emit the full source tree so lazy runtime requires inside wrapper classes
8+
// continue to resolve internal modules from dist/src/** like the old tsc build.
9+
entry: [
10+
'src/**/*.{ts,tsx,js,mts,cts}',
11+
'!src/**/*.d.ts',
12+
'!src/scripts/**',
13+
],
3414
tsconfig: 'tsconfig.lib.json',
3515
outDir: 'dist/src',
3616
format: ['cjs'],

packages/nextjs-mf/src/plugins/container/InvertedContainerPlugin.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import type { Compilation, Compiler, Chunk } from 'webpack';
22
import InvertedContainerRuntimeModule from './InvertedContainerRuntimeModule';
3-
import * as enhancedModule from '@module-federation/enhanced';
43

5-
const enhancedExports =
6-
(enhancedModule as any).default ?? (enhancedModule as any);
7-
const { FederationModulesPlugin, dependencies } = enhancedExports;
4+
type EnhancedModuleExports = typeof import('@module-federation/enhanced');
5+
6+
const loadEnhanced = (): EnhancedModuleExports => {
7+
const enhancedModule = require('@module-federation/enhanced') as
8+
| EnhancedModuleExports
9+
| { default: EnhancedModuleExports };
10+
11+
return (enhancedModule as { default?: EnhancedModuleExports }).default
12+
? (enhancedModule as { default: EnhancedModuleExports }).default
13+
: (enhancedModule as EnhancedModuleExports);
14+
};
815

916
class InvertedContainerPlugin {
1017
public apply(compiler: Compiler): void {
18+
const { FederationModulesPlugin, dependencies } = loadEnhanced();
19+
1120
compiler.hooks.thisCompilation.tap(
1221
'EmbeddedContainerPlugin',
1322
(compilation: Compilation) => {

tools/rslib-plugin/dist/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
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { defineConfig } from 'tsdown';
2+
3+
export default defineConfig([
4+
{
5+
name: 'rslib-plugin-build',
6+
cwd: import.meta.dirname,
7+
entry: {
8+
index: 'src/index.ts',
9+
'executors/build/executor': 'src/executors/build/executor.ts',
10+
'executors/dev/executor': 'src/executors/dev/executor.ts',
11+
'executors/echo/executor': 'src/executors/echo/executor.ts',
12+
},
13+
tsconfig: 'tsconfig.json',
14+
outDir: 'dist/src',
15+
format: ['cjs'],
16+
external: [/^[^./]/],
17+
sourcemap: true,
18+
clean: true,
19+
dts: {
20+
resolver: 'tsc',
21+
},
22+
inlineOnly: false,
23+
skipNodeModulesBundle: true,
24+
unbundle: true,
25+
outExtensions: () => ({
26+
js: '.js',
27+
dts: '.d.ts',
28+
}),
29+
},
30+
]);

0 commit comments

Comments
 (0)