2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 03:29:00 +00:00
books/build/scripts/helpers.mjs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.4 KiB
JavaScript
Raw Normal View History

import fs from 'fs';
import path from 'path';
/**
* Common ESBuild config used for building main process source
* code for both dev and production.
*
* @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'),
],
bundle: true,
sourcemap: true,
sourcesContent: false,
platform: 'node',
target: 'node16',
external: ['knex', 'electron', 'better-sqlite3', 'electron-store'],
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.
*
* Note, this is used only for the main process source code.
*
* 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',
};
});
},
};