Skip to content

Commit

Permalink
Bundle the electron files with esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
whitphx committed Mar 26, 2024
1 parent fbd9245 commit 47f4f3d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
9 changes: 3 additions & 6 deletions packages/desktop/electron/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
"compilerOptions": {
"target": "ESNext",
"module": "commonjs",
"sourceMap": false,
"outDir": "../build",
"rootDir": "../",
"noEmit": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["."],
"exclude": ["./**/*.test.*", "./**/__tests__"]
}
}
4 changes: 2 additions & 2 deletions packages/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"build:web": "craco build && rimraf 'build/**/*.whl' && rimraf 'build/pypi'",
"test": "craco test",
"eject": "craco eject",
"start:electron": "concurrently \"tsc -p electron -w\" \"cross-env NODE_ENV=\"development\" electron .\"",
"build:electron": "tsc -p electron",
"start:electron": "tsc -p electron && cross-env NODE_ENV=development concurrently \"./scripts/build_electron.js --watch\" \"electron .\"",
"build:electron": "tsc -p electron && cross-env NODE_ENV=production ./scripts/build_electron.js",
"build:pyodide": "curl -L https://github.com/pyodide/pyodide/releases/download/0.25.0/pyodide-core-0.25.0.tar.bz2 | tar xj -C ./build --files-from=./pyodide-files.txt",
"build:bin": "tsc -p bin-src && ./scripts/build_bin.js",
"build:wheels": "./scripts/copy_wheels.js",
Expand Down
31 changes: 31 additions & 0 deletions packages/desktop/scripts/build_electron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env node

const { build, context } = require("esbuild");
const path = require("path");

// Build script using esbuild like https://esbuild.github.io/getting-started/#build-scripts

const watch = process.argv.includes("--watch");
const production = process.env.NODE_ENV === "production";

(watch ? context : build)({
entryPoints: [
path.resolve(__dirname, "../electron/main.ts"),
path.resolve(__dirname, "../electron/preload.ts"),
],
bundle: true,
minify: production,
platform: "node",
outdir: path.resolve(__dirname, "../build/electron"),
external: ["electron", "electron-reload"],
define: {
...(process.env.NODE_ENV != null
? {
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
}
: null),
},
logLevel: "info",
})
.then((buildResultOrContext) => watch && buildResultOrContext.watch())
.catch(() => process.exit(1));

0 comments on commit 47f4f3d

Please sign in to comment.