Bundle preload.js

This commit is contained in:
Fedor Indutny 2021-04-07 15:40:12 -07:00 committed by Josh Perez
parent 9c3e3c4331
commit 4fd3ed7242
11 changed files with 205 additions and 232 deletions

View file

@ -5,6 +5,7 @@ import { resolve } from 'path';
// eslint-disable-next-line import/no-extraneous-dependencies
import { Configuration, EnvironmentPlugin, ProvidePlugin } from 'webpack';
import HtmlWebpackPlugin = require('html-webpack-plugin');
import TerserPlugin = require('terser-webpack-plugin');
const context = __dirname;
const { NODE_ENV: mode = 'development' } = process.env;
@ -27,6 +28,7 @@ const csp = `
const stickerCreatorConfig: Configuration = {
context,
mode: mode as Configuration['mode'],
cache: { type: 'filesystem' },
devtool: 'source-map',
entry: [
'react-hot-loader/patch',
@ -89,4 +91,64 @@ const stickerCreatorConfig: Configuration = {
},
};
export default [stickerCreatorConfig];
const EXTERNAL_MODULE = new Set([
'backbone',
'better-sqlite3',
'ffi-napi',
'fs-xattr',
'fsevents',
'got',
'jquery',
'libsignal-client',
'node-fetch',
'node-sass',
'pino',
'proxy-agent',
'ref-array-napi',
'ref-napi',
'ringrtc',
'sharp',
'websocket',
'zkgroup',
]);
const preloadConfig: Configuration = {
context,
mode: mode as Configuration['mode'],
cache: { type: 'filesystem' },
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({
terserOptions: {
mangle: {
keep_fnames: true,
},
},
}),
],
},
target: 'electron-preload',
output: {
path: resolve(context),
filename: 'preload.bundle.js',
publicPath: './',
},
resolve: {
extensions: ['.js'],
alias: {},
},
externals: [
({ request = '' }, callback) => {
if (EXTERNAL_MODULE.has(request)) {
return callback(undefined, `commonjs2 ${request}`);
}
callback();
},
],
};
export default [stickerCreatorConfig, preloadConfig];