From 17f1fb6376e126e706910f1874ffffde68597b0e Mon Sep 17 00:00:00 2001 From: Alex Nisnevich Date: Mon, 4 Jan 2021 13:46:21 -0800 Subject: [PATCH] Reduce compressed bundle size from 2.72 MB to 2.64 MB with some webpack tricks (#1392) * Reduce compressed bundle size from 2.72 MB to 2.64 MB with some webpack tricks * minor --- package.json | 1 + src/common/components/game/Sfx.tsx | 2 +- webpack.config.js | 4 ++-- yarn.lock | 33 +++++++++++++++++++++++++++++- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index e41f0896c..1e44f7fb3 100644 --- a/package.json +++ b/package.json @@ -116,6 +116,7 @@ "@typescript-eslint/parser": "^4.9.0", "awesome-typescript-loader": "^5.0.0", "babel-loader": "^8.0.1", + "babel-plugin-lodash": "^3.3.4", "copy-webpack-plugin": "^4.5.0", "css-loader": "^1.0.0", "csstype": "^2.5.2", diff --git a/src/common/components/game/Sfx.tsx b/src/common/components/game/Sfx.tsx index 97b9d5a26..40f16b618 100644 --- a/src/common/components/game/Sfx.tsx +++ b/src/common/components/game/Sfx.tsx @@ -3,7 +3,7 @@ import * as React from 'react'; import { inBrowser, isFlagSet } from '../../util/browser'; const Sound = inBrowser() ? require('react-sound').default : null; -const soundManager = inBrowser() ? require('soundmanager2').soundManager : null; +const soundManager = inBrowser() ? require('soundmanager2/script/soundmanager2-nodebug').soundManager : null; interface SfxProps { queue: string[] diff --git a/webpack.config.js b/webpack.config.js index 4b6395a06..a8a59398e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -26,7 +26,7 @@ const webpackConfig = { loader: 'babel-loader', options: { babelrc: false, - plugins: ['react-hot-loader/babel', '@babel/plugin-syntax-dynamic-import'] + plugins: ['react-hot-loader/babel', '@babel/plugin-syntax-dynamic-import', 'babel-plugin-lodash'] } }, { @@ -56,10 +56,10 @@ const webpackConfig = { }, plugins: compact([ !isProduction && new webpack.HotModuleReplacementPlugin(), + new webpack.EnvironmentPlugin({ NODE_ENV: 'development', PARSER: null, FIREBASE_DB: null }), new CopyWebpackPlugin([{from: 'static'}]), new webpack.IgnorePlugin(/^canvas$/), new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), // Ignore all locale files of moment.js - new webpack.EnvironmentPlugin({ NODE_ENV: 'development', PARSER: null, FIREBASE_DB: null }) ]), resolve: { extensions: ['.ts', '.tsx', '.js', '.jsx'] diff --git a/yarn.lock b/yarn.lock index 28587c8c0..9cf100884 100644 --- a/yarn.lock +++ b/yarn.lock @@ -112,9 +112,10 @@ dependencies: "@babel/types" "^7.12.7" -"@babel/helper-module-imports@^7.12.1": +"@babel/helper-module-imports@^7.0.0-beta.49", "@babel/helper-module-imports@^7.12.1": version "7.12.5" resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.12.5.tgz#1bfc0229f794988f76ed0a4d4e90860850b54dfb" + integrity sha512-SR713Ogqg6++uexFRORf/+nPXMmWIn80TALu0uaFb+iQIUoR7bOC7zBWyzBs5b3tBBJXuyD0cRu1F15GyzjOWA== dependencies: "@babel/types" "^7.12.5" @@ -177,6 +178,11 @@ version "7.10.4" resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.4.tgz#a78c7a7251e01f616512d31b10adcf52ada5e0d2" +"@babel/helper-validator-identifier@^7.12.11": + version "7.12.11" + resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.12.11.tgz#c9a1f021917dcb5ccf0d4e453e399022981fc9ed" + integrity sha512-np/lG3uARFybkoHokJUmf1QfEvRVCPbmQeUQpKow5cQ3xWrV9i3rUHodKDJPQfTVX61qKi+UdYk8kik84n7XOw== + "@babel/helpers@^7.12.5": version "7.12.5" resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.12.5.tgz#1a1ba4a768d9b58310eda516c449913fe647116e" @@ -373,6 +379,15 @@ lodash "^4.17.10" to-fast-properties "^2.0.0" +"@babel/types@^7.0.0-beta.49": + version "7.12.12" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.12.12.tgz#4608a6ec313abbd87afa55004d373ad04a96c299" + integrity sha512-lnIX7piTxOH22xE7fDXDbSHg9MM1/6ORnafpJmov5rs0kX5g4BZxeXNJLXsMRiO0U5Rb8/FvMS6xlTnTHvxonQ== + dependencies: + "@babel/helper-validator-identifier" "^7.12.11" + lodash "^4.17.19" + to-fast-properties "^2.0.0" + "@babel/types@^7.10.4", "@babel/types@^7.11.0", "@babel/types@^7.12.1", "@babel/types@^7.12.5", "@babel/types@^7.12.7", "@babel/types@^7.3.3": version "7.12.7" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.12.7.tgz#6039ff1e242640a29452c9ae572162ec9a8f5d13" @@ -2104,6 +2119,17 @@ babel-plugin-jest-hoist@^26.6.2: "@types/babel__core" "^7.0.0" "@types/babel__traverse" "^7.0.6" +babel-plugin-lodash@^3.3.4: + version "3.3.4" + resolved "https://registry.yarnpkg.com/babel-plugin-lodash/-/babel-plugin-lodash-3.3.4.tgz#4f6844358a1340baed182adbeffa8df9967bc196" + integrity sha512-yDZLjK7TCkWl1gpBeBGmuaDIFhZKmkoL+Cu2MUUjv5VxUZx/z7tBGBCBcQs5RI1Bkz5LLmNdjx7paOyQtMovyg== + dependencies: + "@babel/helper-module-imports" "^7.0.0-beta.49" + "@babel/types" "^7.0.0-beta.49" + glob "^7.1.1" + lodash "^4.17.10" + require-package-name "^2.0.1" + babel-preset-current-node-syntax@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.0.0.tgz#cf5feef29551253471cfa82fc8e0f5063df07a77" @@ -9527,6 +9553,11 @@ require-main-filename@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" +require-package-name@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/require-package-name/-/require-package-name-2.0.1.tgz#c11e97276b65b8e2923f75dabf5fb2ef0c3841b9" + integrity sha1-wR6XJ2tluOKSP3Xav1+y7ww4Qbk= + requires-port@1.0.x, requires-port@^1.0.0, requires-port@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"