2022-02-11 21:38:52 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
const esbuild = require('esbuild');
|
|
|
|
const path = require('path');
|
|
|
|
const glob = require('glob');
|
|
|
|
|
|
|
|
const ROOT_DIR = path.join(__dirname, '..');
|
|
|
|
|
|
|
|
const watch = process.argv.some(argv => argv === '-w' || argv === '--watch');
|
|
|
|
const isProd = process.argv.some(argv => argv === '-prod' || argv === '--prod');
|
|
|
|
|
|
|
|
const nodeDefaults = {
|
|
|
|
platform: 'node',
|
2022-03-29 01:47:29 +00:00
|
|
|
target: 'es2020',
|
2022-02-11 21:38:52 +00:00
|
|
|
sourcemap: isProd ? false : 'inline',
|
|
|
|
// Otherwise React components get renamed
|
|
|
|
// See: https://github.com/evanw/esbuild/issues/1147
|
|
|
|
keepNames: true,
|
|
|
|
logLevel: 'info',
|
|
|
|
watch,
|
|
|
|
};
|
|
|
|
|
|
|
|
const bundleDefaults = {
|
|
|
|
...nodeDefaults,
|
2022-02-25 20:36:42 +00:00
|
|
|
define: {
|
|
|
|
'process.env.NODE_ENV': isProd ? '"production"' : '"development"',
|
|
|
|
},
|
2022-02-11 21:38:52 +00:00
|
|
|
bundle: true,
|
|
|
|
external: [
|
2022-02-28 17:39:39 +00:00
|
|
|
// Native libraries
|
2022-03-24 21:47:21 +00:00
|
|
|
'@signalapp/libsignal-client',
|
|
|
|
'@signalapp/libsignal-client/zkgroup',
|
2022-12-14 20:48:36 +00:00
|
|
|
'@signalapp/better-sqlite3',
|
2022-02-28 17:39:39 +00:00
|
|
|
'electron',
|
2022-02-11 21:38:52 +00:00
|
|
|
'fs-xattr',
|
|
|
|
'fsevents',
|
2022-02-28 17:39:39 +00:00
|
|
|
'mac-screen-capture-permissions',
|
|
|
|
'ringrtc',
|
|
|
|
'sass',
|
2022-12-16 02:03:01 +00:00
|
|
|
'bufferutil',
|
|
|
|
'utf-8-validate',
|
2022-02-28 17:39:39 +00:00
|
|
|
|
|
|
|
// Things that don't bundle well
|
2022-02-11 21:38:52 +00:00
|
|
|
'got',
|
|
|
|
'jquery',
|
|
|
|
'node-fetch',
|
|
|
|
'pino',
|
|
|
|
'proxy-agent',
|
2022-12-16 02:03:01 +00:00
|
|
|
'websocket',
|
2022-02-28 17:39:39 +00:00
|
|
|
|
|
|
|
// Large libraries (3.7mb total)
|
|
|
|
// See: https://esbuild.github.io/api/#analyze
|
|
|
|
'emoji-datasource',
|
|
|
|
'fabric',
|
|
|
|
'google-libphonenumber',
|
|
|
|
'moment',
|
|
|
|
'quill',
|
2022-02-11 21:38:52 +00:00
|
|
|
|
|
|
|
// Uses fast-glob and dynamic requires
|
|
|
|
'./preload_test',
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
// App, tests, and scripts
|
|
|
|
esbuild.build({
|
|
|
|
...nodeDefaults,
|
|
|
|
format: 'cjs',
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
entryPoints: glob
|
2022-06-14 01:48:07 +00:00
|
|
|
.sync('{app,ts,sticker-creator}/**/*.{ts,tsx}', {
|
2022-02-11 21:38:52 +00:00
|
|
|
nodir: true,
|
|
|
|
root: ROOT_DIR,
|
|
|
|
})
|
|
|
|
.filter(file => !file.endsWith('.d.ts')),
|
|
|
|
outdir: path.join(ROOT_DIR),
|
|
|
|
});
|
|
|
|
|
|
|
|
// Preload bundle
|
|
|
|
esbuild.build({
|
|
|
|
...bundleDefaults,
|
|
|
|
mainFields: ['browser', 'main'],
|
2022-06-15 18:21:03 +00:00
|
|
|
entryPoints: [path.join(ROOT_DIR, 'ts', 'windows', 'main', 'preload.ts')],
|
2022-02-11 21:38:52 +00:00
|
|
|
outfile: path.join(ROOT_DIR, 'preload.bundle.js'),
|
|
|
|
});
|