AFFiNE/apps/electron/scripts/common.mjs

75 lines
2.0 KiB
JavaScript
Raw Normal View History

2023-04-25 02:53:36 +03:00
import { resolve } from 'node:path';
import { fileURLToPath } from 'url';
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
// 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-06-13 05:01:43 +03:00
/** @return {{layers: import('esbuild').BuildOptions, workers: import('esbuild').BuildOptions}} */
2023-04-25 02:53:36 +03:00
export const config = () => {
const define = Object.fromEntries([
['process.env.NODE_ENV', `"${mode}"`],
2023-05-31 06:09:18 +03:00
['process.env.USE_WORKER', '"true"'],
]);
if (DEV_SERVER_URL) {
define['process.env.DEV_SERVER_URL'] = `"${DEV_SERVER_URL}"`;
}
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-05-31 06:09:18 +03:00
],
2023-06-13 05:01:43 +03:00
entryNames: '[dir]',
outdir: resolve(electronDir, './dist'),
bundle: true,
target: `node${NODE_MAJOR_VERSION}`,
platform: 'node',
external: [
'electron',
'electron-updater',
'@toeverything/plugin-infra',
'yjs',
],
define: define,
format: 'cjs',
loader: {
'.node': 'copy',
},
assetNames: '[name]',
treeShaking: true,
},
2023-06-13 05:01:43 +03:00
workers: {
entryPoints: [
resolve(electronDir, './src/main/workers/plugin.worker.ts'),
],
entryNames: '[dir]/[name]',
outdir: resolve(electronDir, './dist/workers'),
bundle: true,
target: `node${NODE_MAJOR_VERSION}`,
platform: 'node',
external: ['@toeverything/plugin-infra', 'async-call-rpc'],
define: define,
2023-06-13 05:01:43 +03:00
format: 'cjs',
loader: {
'.node': 'copy',
},
assetNames: '[name]',
treeShaking: true,
},
};
2023-03-16 17:58:21 +03:00
};