Skip to content

Commit f33d9d5

Browse files
committed
feat: enhance wokwi-client-js with browser bundling support
1 parent ead3b79 commit f33d9d5

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

packages/wokwi-client-js/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"types": "./dist/index.d.ts",
1111
"import": "./dist/index.js"
1212
},
13+
"./browser": {
14+
"types": "./dist/index.d.ts",
15+
"import": "./dist/wokwi-client-js.browser.js"
16+
},
1317
"./transport/MessagePortTransport.js": {
1418
"types": "./dist/transport/MessagePortTransport.d.ts",
1519
"import": "./dist/transport/MessagePortTransport.js"
@@ -24,7 +28,8 @@
2428
],
2529
"scripts": {
2630
"prebuild": "pnpm run clean",
27-
"build": "tsc",
31+
"build": "tsc && pnpm run build:browser",
32+
"build:browser": "node tools/bundle-browser.js",
2833
"clean": "rimraf dist",
2934
"lint": "eslint src/**/*.ts",
3035
"lint:fix": "eslint src/**/*.ts --fix"
@@ -49,6 +54,7 @@
4954
},
5055
"devDependencies": {
5156
"@types/ws": "^8.18.1",
57+
"esbuild": "^0.25.2",
5258
"rimraf": "^5.0.0",
5359
"typescript": "^5.2.2"
5460
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { build } from 'esbuild';
2+
import { fileURLToPath } from 'url';
3+
import { dirname, join } from 'path';
4+
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = dirname(__filename);
7+
const rootDir = join(__dirname, '..');
8+
9+
const options = {
10+
entryPoints: [join(rootDir, 'src/index.ts')],
11+
outfile: join(rootDir, 'dist/wokwi-client-js.browser.js'),
12+
bundle: true,
13+
platform: 'browser',
14+
format: 'esm',
15+
target: 'es2020',
16+
// Explicitly mark Node.js-only packages as external
17+
external: ['ws', 'stream', 'buffer'],
18+
banner: {
19+
js: `// Browser bundle of wokwi-client-js
20+
// Note: serialMonitorWritable() requires Node.js and won't work in browsers
21+
// Use MessagePortTransport for browser communication with Wokwi Simulator
22+
`,
23+
},
24+
};
25+
26+
// Build the browser bundle
27+
build(options)
28+
.then(() => {
29+
console.log('✓ Browser bundle created: dist/wokwi-client-js.browser.js');
30+
})
31+
.catch((error) => {
32+
console.error('✗ Browser bundle failed:', error);
33+
process.exit(1);
34+
});
35+

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)