-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.config.js
More file actions
93 lines (84 loc) · 2.06 KB
/
esbuild.config.js
File metadata and controls
93 lines (84 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const esbuild = require('esbuild');
const path = require('path');
const fs = require('fs/promises');
const mainConfig = {
entryPoints: ['src/index.ts'],
bundle: true,
platform: 'node',
target: 'node18',
outfile: '.build/main.js',
format: 'esm',
external: [
'electron',
'electron-store',
'fs-extra',
'@blockingmachine/core',
'electron-devtools-installer'
],
define: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production')
}
};
const rendererConfig = {
entryPoints: ['src/renderer.tsx'],
bundle: true,
platform: 'browser',
target: 'chrome96',
outfile: '.build/renderer.js',
format: 'esm',
loader: {
'.css': 'css',
},
plugins: [
{
name: 'css-loader',
setup(build) {
build.onLoad({ filter: /\.css$/ }, async (args) => {
const css = await fs.readFile(args.path, 'utf8');
const contents = `
const style = document.createElement('style');
style.textContent = ${JSON.stringify(css)};
document.head.appendChild(style);
export default {};
`;
return { contents, loader: 'js' };
});
},
},
],
inject: ['./src/css-inject.js'],
};
const preloadConfig = {
entryPoints: ['src/preload.ts'],
bundle: true,
platform: 'node',
target: 'node22',
outfile: '.build/preload.js',
format: 'esm',
external: ['electron'],
};
async function buildApp() {
try {
await fs.mkdir('.build', { recursive: true });
await Promise.all([
esbuild.build(mainConfig),
esbuild.build(rendererConfig),
esbuild.build(preloadConfig),
fs.copyFile(
path.join(__dirname, 'src', 'index.html'),
path.join(__dirname, '.build', 'index.html')
),
]);
console.log('Build completed successfully');
} catch (error) {
console.error('Build failed:', error);
process.exit(1);
}
}
const mainWindow = {
loadFile: (filePath) => {
console.log(`Loading file: ${filePath}`);
},
};
mainWindow.loadFile(path.join(__dirname, 'index.html'));
buildApp();