2023-04-25 02:53:36 +03:00
|
|
|
import { resolve } from 'node:path';
|
|
|
|
|
|
|
|
import { fileURLToPath } from 'url';
|
|
|
|
|
2023-06-02 11:28:47 +03:00
|
|
|
export const electronDir = fileURLToPath(new URL('..', import.meta.url));
|
|
|
|
|
|
|
|
export const rootDir = resolve(electronDir, '..', '..');
|
|
|
|
|
2023-04-25 02:53:36 +03:00
|
|
|
export const NODE_MAJOR_VERSION = 18;
|
2023-03-16 17:58:21 +03:00
|
|
|
|
2023-05-09 10:30:01 +03:00
|
|
|
// hard-coded for now:
|
|
|
|
// fixme(xp): report error if app is not running on DEV_SERVER_URL
|
|
|
|
const DEV_SERVER_URL = process.env.DEV_SERVER_URL;
|
|
|
|
|
|
|
|
/** @type 'production' | 'development'' */
|
|
|
|
const mode = (process.env.NODE_ENV = process.env.NODE_ENV || 'development');
|
|
|
|
|
2023-07-26 00:32:34 +03:00
|
|
|
/** @return {{layers: import('esbuild').BuildOptions}} */
|
2023-04-25 02:53:36 +03:00
|
|
|
export const config = () => {
|
2023-05-09 10:30:01 +03:00
|
|
|
const define = Object.fromEntries([
|
|
|
|
['process.env.NODE_ENV', `"${mode}"`],
|
2023-05-31 06:09:18 +03:00
|
|
|
['process.env.USE_WORKER', '"true"'],
|
2023-05-09 10:30:01 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
if (DEV_SERVER_URL) {
|
|
|
|
define['process.env.DEV_SERVER_URL'] = `"${DEV_SERVER_URL}"`;
|
|
|
|
}
|
|
|
|
|
2023-04-11 21:42:36 +03:00
|
|
|
return {
|
2023-06-13 05:01:43 +03:00
|
|
|
layers: {
|
2023-05-31 06:09:18 +03:00
|
|
|
entryPoints: [
|
2023-06-13 05:01:43 +03:00
|
|
|
resolve(electronDir, './src/main/index.ts'),
|
|
|
|
resolve(electronDir, './src/preload/index.ts'),
|
|
|
|
resolve(electronDir, './src/helper/index.ts'),
|
2023-07-29 23:57:23 +03:00
|
|
|
resolve(electronDir, './src/worker/plugin.ts'),
|
2023-05-31 06:09:18 +03:00
|
|
|
],
|
2023-06-13 05:01:43 +03:00
|
|
|
entryNames: '[dir]',
|
|
|
|
outdir: resolve(electronDir, './dist'),
|
2023-04-11 21:42:36 +03:00
|
|
|
bundle: true,
|
2023-04-18 12:50:29 +03:00
|
|
|
target: `node${NODE_MAJOR_VERSION}`,
|
2023-04-11 21:42:36 +03:00
|
|
|
platform: 'node',
|
2023-07-10 11:03:18 +03:00
|
|
|
external: [
|
|
|
|
'electron',
|
|
|
|
'electron-updater',
|
|
|
|
'@toeverything/plugin-infra',
|
|
|
|
'yjs',
|
|
|
|
],
|
2023-04-11 21:42:36 +03:00
|
|
|
define: define,
|
2023-05-09 10:30:01 +03:00
|
|
|
format: 'cjs',
|
2023-05-17 07:36:51 +03:00
|
|
|
loader: {
|
|
|
|
'.node': 'copy',
|
|
|
|
},
|
|
|
|
assetNames: '[name]',
|
2023-05-17 12:22:49 +03:00
|
|
|
treeShaking: true,
|
2023-04-11 21:42:36 +03:00
|
|
|
},
|
|
|
|
};
|
2023-03-16 17:58:21 +03:00
|
|
|
};
|