Skip to content

Commit 99ecb31

Browse files
feat(esbuild): Esbuild support (#2473)
Co-authored-by: ScriptedAlchemy <[email protected]>
1 parent 45f0d80 commit 99ecb31

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+4553
-205
lines changed

.changeset/brown-apricots-study.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/esbuild': patch
3+
---
4+
5+
Esbuild federation plugin

.changeset/sweet-mangos-do.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/esbuild': patch
3+
---
4+
5+
update skip share of internals

.cursorignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88
./packages/typescript
99
./packages/native-*
1010
./apps
11+
**/configCases
12+
apps/**
13+
*.snap

apps/esbuild/build.js

Whitespace-only changes.

apps/esbuild/build/build-common.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//@ts-nocheck
2+
3+
const esbuild = require('esbuild');
4+
const path = require('path');
5+
const fs = require('fs');
6+
const { moduleFederationPlugin } = require('@module-federation/esbuild/plugin');
7+
8+
async function buildProject(projectName, watch) {
9+
const tsConfig = 'tsconfig.json';
10+
const outputPath = path.join('dist', projectName);
11+
12+
fs.rmSync(outputPath, { force: true, recursive: true });
13+
14+
await esbuild.build({
15+
entryPoints: [path.join(projectName, 'main.ts')],
16+
outdir: outputPath,
17+
bundle: true,
18+
platform: 'browser',
19+
format: 'esm',
20+
mainFields: ['es2020', 'browser', 'module', 'main'],
21+
conditions: ['es2022', 'es2015', 'module'],
22+
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
23+
loader: { '.ts': 'ts' },
24+
tsconfig: tsConfig,
25+
splitting: true,
26+
plugins: [
27+
moduleFederationPlugin(
28+
require(path.join('../', projectName, 'federation.config.js')),
29+
),
30+
],
31+
watch,
32+
});
33+
34+
['index.html', 'favicon.ico', 'styles.css'].forEach((file) => {
35+
fs.copyFileSync(path.join(projectName, file), path.join(outputPath, file));
36+
});
37+
}
38+
39+
module.exports = { buildProject };

apps/esbuild/build/build-mfe1.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const { buildProject } = require('./build-common');
2+
3+
const watch = process.argv.includes('--watch');
4+
buildProject('mfe1', watch);

apps/esbuild/build/build-shell.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const { buildProject } = require('./build-common');
2+
3+
const watch = process.argv.includes('--watch');
4+
buildProject('shell', watch);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var _data = '';
2+
3+
export function setData(data: string): void {
4+
_data = data;
5+
}
6+
7+
export function getData(): string {
8+
return _data;
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "shared-lib",
3+
"version": "0.0.1",
4+
"main": "./index.ts"
5+
}

apps/esbuild/mfe1/app.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
export function App() {
3+
const [state, setState] = React.useState(null);
4+
React.useEffect(() => {
5+
setState('Hooks work');
6+
});
7+
8+
return (
9+
<div id="container">
10+
<h1>Flights</h1>
11+
<div>
12+
<input type="text" placeholder="From"></input>
13+
</div>
14+
<div>
15+
<input type="text" placeholder="To"></input>
16+
</div>
17+
<div>
18+
<button id="search">Search!</button>
19+
<button id="terms">Terms...</button>
20+
</div>
21+
<p>testing hooks: {state}</p>
22+
</div>
23+
);
24+
}

0 commit comments

Comments
 (0)