2023-06-20 13:59:25 +00:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Common ESBuild config used for building main process source
|
|
|
|
* code for both dev and production.
|
2023-06-21 06:30:22 +00:00
|
|
|
*
|
2023-06-20 13:59:25 +00:00
|
|
|
* @param {string} root
|
|
|
|
* @returns {import('esbuild').BuildOptions}
|
|
|
|
*/
|
|
|
|
export function getMainProcessCommonConfig(root) {
|
|
|
|
return {
|
2023-07-10 07:34:14 +00:00
|
|
|
entryPoints: [
|
|
|
|
path.join(root, 'main.ts'),
|
|
|
|
path.join(root, 'main', 'preload.ts'),
|
|
|
|
],
|
2023-06-20 13:59:25 +00:00
|
|
|
bundle: true,
|
|
|
|
sourcemap: true,
|
|
|
|
sourcesContent: false,
|
|
|
|
platform: 'node',
|
|
|
|
target: 'node16',
|
2023-06-21 06:30:22 +00:00
|
|
|
external: ['knex', 'electron', 'better-sqlite3', 'electron-store'],
|
2023-06-20 13:59:25 +00:00
|
|
|
plugins: [excludeVendorFromSourceMap],
|
|
|
|
write: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ESBuild plugin used to prevent source maps from being generated for
|
|
|
|
* packages inside node_modules, only first-party code source maps
|
|
|
|
* are to be included.
|
2023-06-21 06:30:22 +00:00
|
|
|
*
|
2023-06-20 13:59:25 +00:00
|
|
|
* Note, this is used only for the main process source code.
|
2023-06-21 06:30:22 +00:00
|
|
|
*
|
2023-06-20 13:59:25 +00:00
|
|
|
* source: https://github.com/evanw/esbuild/issues/1685#issuecomment-944916409
|
|
|
|
* @type {import('esbuild').Plugin}
|
|
|
|
*/
|
|
|
|
export const excludeVendorFromSourceMap = {
|
|
|
|
name: 'excludeVendorFromSourceMap',
|
|
|
|
setup(build) {
|
|
|
|
build.onLoad({ filter: /node_modules/ }, (args) => {
|
|
|
|
if (args.path.endsWith('.json')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
contents:
|
|
|
|
fs.readFileSync(args.path, 'utf8') +
|
|
|
|
'\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==',
|
|
|
|
loader: 'default',
|
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|