2023-04-18 12:50:29 +03:00
|
|
|
const NODE_MAJOR_VERSION = 18;
|
2023-03-16 17:58:21 +03:00
|
|
|
|
2023-03-28 02:03:11 +03:00
|
|
|
const nativeNodeModulesPlugin = {
|
|
|
|
name: 'native-node-modules',
|
|
|
|
setup(build) {
|
|
|
|
// Mark native Node.js modules as external
|
|
|
|
build.onResolve({ filter: /\.node$/, namespace: 'file' }, args => {
|
|
|
|
return { path: args.path, external: true };
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-04-11 21:42:36 +03:00
|
|
|
// List of env that will be replaced by esbuild
|
|
|
|
const ENV_MACROS = ['AFFINE_GOOGLE_CLIENT_ID', 'AFFINE_GOOGLE_CLIENT_SECRET'];
|
2023-03-16 17:58:21 +03:00
|
|
|
|
2023-04-11 21:42:36 +03:00
|
|
|
/** @return {{main: import('esbuild').BuildOptions, preload: import('esbuild').BuildOptions}} */
|
|
|
|
export default () => {
|
|
|
|
const define = Object.fromEntries(
|
|
|
|
ENV_MACROS.map(key => [
|
|
|
|
'process.env.' + key,
|
|
|
|
JSON.stringify(process.env[key] ?? ''),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
return {
|
|
|
|
main: {
|
|
|
|
entryPoints: ['layers/main/src/index.ts'],
|
|
|
|
outdir: 'dist/layers/main',
|
|
|
|
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-04-21 18:30:49 +03:00
|
|
|
external: ['electron', 'yjs', 'better-sqlite3'],
|
2023-04-11 21:42:36 +03:00
|
|
|
plugins: [nativeNodeModulesPlugin],
|
|
|
|
define: define,
|
|
|
|
},
|
|
|
|
preload: {
|
|
|
|
entryPoints: ['layers/preload/src/index.ts'],
|
|
|
|
outdir: 'dist/layers/preload',
|
|
|
|
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',
|
|
|
|
external: ['electron'],
|
|
|
|
define: define,
|
|
|
|
},
|
|
|
|
};
|
2023-03-16 17:58:21 +03:00
|
|
|
};
|