Skip to content

chore: esm sample #4342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions esm/host/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Local
.DS_Store
*.local
*.log*

# Dist
node_modules
dist/

# IDE
.vscode/*
!.vscode/extensions.json
.idea
29 changes: 29 additions & 0 deletions esm/host/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Rsbuild project

## Setup

Install the dependencies:

```bash
pnpm install
```

## Get started

Start the dev server:

```bash
pnpm dev
```

Build the app for production:

```bash
pnpm build
```

Preview the production build locally:

```bash
pnpm preview
```
20 changes: 20 additions & 0 deletions esm/host/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "host",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"build": "rsbuild build",
"dev": "rsbuild dev",
"preview": "rsbuild preview"
},
"dependencies": {
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@module-federation/rsbuild-plugin": "0.0.0-next-20250228220829",
"@rsbuild/core": "^1.2.8",
"@rsbuild/plugin-react": "^1.1.0"
}
}
Empty file added esm/host/public/.gitkeep
Empty file.
49 changes: 49 additions & 0 deletions esm/host/rsbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';

export default defineConfig({
entry: {
main: './src/index.jsx',
app: './src/app.jsx',
},
html: {
scriptLoading: 'module',
},
dev: {
writeToDisk: true,
},
tools: {
rspack: {
experiments: {
outputModule: true,
},
externalsType: 'module',
output: {
chunkFormat: 'module',
chunkLoading: 'import',
workerChunkLoading: 'import',
wasmLoading: 'fetch',
library: { type: 'module' },
module: true,
},
optimization: {
runtimeChunk: 'single',
},
},
},
plugins: [
pluginReact({ splitChunks: { react: false, router: false } }),
pluginModuleFederation({
name: 'host',
remoteType: 'module',
remotes: {
remote: 'http://localhost:3001/static/remoteEntry.js',
},
shared: {
react: { singleton: true },
'react-dom': { singleton: true },
},
}),
],
});
26 changes: 26 additions & 0 deletions esm/host/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
body {
margin: 0;
color: #fff;
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
background-image: linear-gradient(to bottom, #020917, #101725);
}

.content {
display: flex;
min-height: 100vh;
line-height: 1.1;
text-align: center;
flex-direction: column;
justify-content: center;
}

.content h1 {
font-size: 3.6rem;
font-weight: 700;
}

.content p {
font-size: 1.2rem;
font-weight: 400;
opacity: 0.5;
}
12 changes: 12 additions & 0 deletions esm/host/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import './App.css';

const App = () => {
return (
<div className="content">
<h1>Rsbuild with React</h1>
<p>Start building amazing things with Rsbuild.</p>
</div>
);
};

export default App;
10 changes: 10 additions & 0 deletions esm/host/src/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
8 changes: 8 additions & 0 deletions esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "esm-sample",
"version": "1.0.0",
"scripts": {
"start": "cd host; pnpm run dev",
"dev": "pnpm --filter \"./host\" dev & pnpm --filter \"./remote\" dev"
}
}
13 changes: 13 additions & 0 deletions esm/remote/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Local
.DS_Store
*.local
*.log*

# Dist
node_modules
dist/

# IDE
.vscode/*
!.vscode/extensions.json
.idea
29 changes: 29 additions & 0 deletions esm/remote/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Rsbuild project

## Setup

Install the dependencies:

```bash
pnpm install
```

## Get started

Start the dev server:

```bash
pnpm dev
```

Build the app for production:

```bash
pnpm build
```

Preview the production build locally:

```bash
pnpm preview
```
20 changes: 20 additions & 0 deletions esm/remote/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "remote",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"build": "rsbuild build",
"dev": "rsbuild dev",
"preview": "rsbuild preview"
},
"dependencies": {
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@module-federation/rsbuild-plugin": "0.0.0-next-20250228220829",
"@rsbuild/core": "^1.2.8",
"@rsbuild/plugin-react": "^1.1.0"
}
}
Empty file added esm/remote/public/.gitkeep
Empty file.
66 changes: 66 additions & 0 deletions esm/remote/rsbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';

export default defineConfig({
html: {
scriptLoading: 'module',
},
source: {


entry: {
main: './src/index.js',
other: {
import: './src/other.jsx'
},
bs: './src/bootstrap.jsx',
},
},
server: {
port: 3001,
},
dev: {
writeToDisk: true,
},
tools: {
rspack: {
experiments: {
outputModule: true,
topLevelAwait: true

},
externalsType: 'module',
output: {
chunkFormat: 'module',
chunkLoading: 'import',
workerChunkLoading: 'import',
wasmLoading: 'fetch',
library: { type: 'module' },
module: true,
asyncChunks: true
},
optimization: {
runtimeChunk: 'single',
},
},
},
plugins: [
pluginReact({ splitChunks: { react: false, router: false } }),
pluginModuleFederation({
name: 'remote',
runtime: false,
filename: 'static/remoteEntry.js',
library: {
type: 'module',
},
exposes: {
'./App': './src/App.jsx',
},
shared: {
react: { singleton: true },
'react-dom': { singleton: true },
},
}),
],
});
26 changes: 26 additions & 0 deletions esm/remote/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
body {
margin: 0;
color: #fff;
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
background-image: linear-gradient(to bottom, #020917, #101725);
}

.content {
display: flex;
min-height: 100vh;
line-height: 1.1;
text-align: center;
flex-direction: column;
justify-content: center;
}

.content h1 {
font-size: 3.6rem;
font-weight: 700;
}

.content p {
font-size: 1.2rem;
font-weight: 400;
opacity: 0.5;
}
12 changes: 12 additions & 0 deletions esm/remote/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import './App.css';

const App = () => {
return (
<div className="content">
<h1>Rsbuild with React</h1>
<p>Start building amazing things with Rsbuild.</p>
</div>
);
};

export default App;
10 changes: 10 additions & 0 deletions esm/remote/src/bootstrap.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
1 change: 1 addition & 0 deletions esm/remote/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import('./bootstrap.jsx')
12 changes: 12 additions & 0 deletions esm/remote/src/other.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import './App.css';

const App = () => {
return (
<div className="content">
<h1>Rsbuild with React</h1>
<p>Start building amazing things with Rsbuild.</p>
</div>
);
};

export default App;
13 changes: 13 additions & 0 deletions esm/rspack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Local
.DS_Store
*.local
*.log*

# Dist
node_modules
dist/

# IDE
.vscode/*
!.vscode/extensions.json
.idea
Loading