From 69b7301b9d5d33c259ea032f5e3a79c937ebc8cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Tue, 22 Sep 2020 10:20:55 +0200 Subject: [PATCH] fix(build) reduce bundle size by about 700K app.bundle.js before: 3851549 after: 4506493. The culprit for the bloat was Olm. It feature-detects the environment in order to pick a suitable random byte generator, and alas Webpack includes the None crypto pollyfill. This is due to the existence of the "node" block in our Webpack configuration file. The solution is to provide empty modules to make bundling work, as we did already for the fs module, since we know they are not used at runtime. --- webpack.config.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 6f358f9c0..48d1c6626 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -142,7 +142,8 @@ const config = { // value that is a mock (/index.js). __filename: true, - // Provide an empty 'fs' module. + // Provide some empty Node modules (required by olm). + crypto: 'empty', fs: 'empty' }, optimization: { @@ -190,7 +191,7 @@ module.exports = [ entry: { 'app.bundle': './app.js' }, - performance: getPerformanceHints(4.5 * 1024 * 1024) + performance: getPerformanceHints(4 * 1024 * 1024) }), Object.assign({}, config, { entry: {