2021-04-14 19:43:11 +00:00
|
|
|
// Copyright 2019-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { resolve } from 'path';
|
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
|
|
import { Configuration } from 'webpack';
|
|
|
|
import TerserPlugin = require('terser-webpack-plugin');
|
|
|
|
|
|
|
|
const context = __dirname;
|
|
|
|
const { NODE_ENV: mode = 'development' } = process.env;
|
|
|
|
|
|
|
|
const EXTERNAL_MODULE = new Set([
|
2021-05-20 21:54:03 +00:00
|
|
|
'@signalapp/signal-client',
|
2021-11-11 15:24:28 +00:00
|
|
|
'@signalapp/signal-client/zkgroup',
|
2021-04-14 19:43:11 +00:00
|
|
|
'backbone',
|
|
|
|
'better-sqlite3',
|
|
|
|
'fs-xattr',
|
|
|
|
'fsevents',
|
|
|
|
'got',
|
|
|
|
'jquery',
|
2021-05-20 21:54:03 +00:00
|
|
|
'mac-screen-capture-permissions',
|
2021-04-14 19:43:11 +00:00
|
|
|
'node-fetch',
|
|
|
|
'node-sass',
|
|
|
|
'pino',
|
|
|
|
'proxy-agent',
|
|
|
|
'ringrtc',
|
|
|
|
'sharp',
|
|
|
|
'websocket',
|
|
|
|
|
|
|
|
// Uses fast-glob and dynamic requires
|
2021-08-11 19:29:07 +00:00
|
|
|
'./preload_test',
|
|
|
|
|
|
|
|
// Needs to exports `electronRequire`
|
|
|
|
'./ts/CI',
|
2021-04-14 19:43:11 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
const preloadConfig: Configuration = {
|
|
|
|
context,
|
|
|
|
mode: mode as Configuration['mode'],
|
|
|
|
devtool: mode === 'development' ? 'inline-source-map' : false,
|
|
|
|
entry: ['./preload.js'],
|
|
|
|
// Stack-traces have to be readable so don't mangle function names.
|
|
|
|
optimization: {
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin({
|
2021-08-11 19:29:07 +00:00
|
|
|
parallel: true,
|
2021-04-14 19:43:11 +00:00
|
|
|
terserOptions: {
|
2021-08-11 19:29:07 +00:00
|
|
|
mangle: false,
|
|
|
|
keep_classnames: true,
|
|
|
|
keep_fnames: true,
|
2021-04-14 19:43:11 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
target: 'electron-preload',
|
|
|
|
output: {
|
|
|
|
path: resolve(context),
|
|
|
|
filename: 'preload.bundle.js',
|
|
|
|
publicPath: './',
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.js'],
|
|
|
|
alias: {},
|
2021-04-14 23:58:26 +00:00
|
|
|
mainFields: ['browser', 'main'],
|
2021-04-14 19:43:11 +00:00
|
|
|
},
|
|
|
|
externals: [
|
|
|
|
({ request = '' }, callback) => {
|
|
|
|
if (EXTERNAL_MODULE.has(request)) {
|
|
|
|
return callback(undefined, `commonjs2 ${request}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
callback();
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
export default [preloadConfig];
|