From 90b04f85b3ec7a425cbd6113262df7d1bd5c3a5b Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 27 Oct 2022 13:07:22 -0500 Subject: [PATCH] webpack: add hack to remove unused icons This follows the suggestions from [1] to reduce the package size by only including the icons we are actually using. This gets the main module small enough to avoid the CRA "The bundle size is significantly larger than recommended." warning (gzipped size is < 512KB). [1]: https://github.com/palantir/blueprint/issues/2193 --- config/webpack.config.js | 4 ++ src/blueprintjs-icons.js | 84 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 src/blueprintjs-icons.js diff --git a/config/webpack.config.js b/config/webpack.config.js index 096d8b87..386dbe5b 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -586,6 +586,10 @@ module.exports = function (webpackEnv) { ].filter(Boolean), }, plugins: [ + // https://github.com/palantir/blueprint/issues/2193 + new webpack.NormalModuleReplacementPlugin( + /.*\/@blueprintjs\/icons\/lib\/esm\/iconSvgPaths.*/, + path.resolve(__dirname, "../src/blueprintjs-icons.js")), new CopyPlugin({ patterns: [ { diff --git a/src/blueprintjs-icons.js b/src/blueprintjs-icons.js new file mode 100644 index 00000000..9d5a175c --- /dev/null +++ b/src/blueprintjs-icons.js @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2022 The Pybricks Authors + +// HACK: Prevent webpack from picking up all icons. +// https://github.com/palantir/blueprint/issues/2193 + +import { + Add, + Archive, + Blank, + Chat, + ChevronDown, + ChevronRight, + Clipboard, + Code, + Cog, + Cross, + Disable, + Document, + Download, + Duplicate, + Edit, + Error, + Export, + Help, + Import, + InfoSign, + Lightbulb, + Play, + Plus, + Redo, + Refresh, + Share, + Tick, + TickCircle, + Trash, + Undo, + Virus, +} from '@blueprintjs/icons/lib/esm/generated/16px/paths'; +import { + Cog as Cog20, + Document as Document20, +} from '@blueprintjs/icons/lib/esm/generated/20px/paths'; +import { pascalCase } from 'change-case'; + +export function iconNameToPathsRecordKey(name) { + return pascalCase(name); +} + +export const IconSvgPaths16 = { + Add, + Archive, + Blank, + Chat, + ChevronDown, + ChevronRight, + Clipboard, + Code, + Cog, + Cross, + Disable, + Document, + Download, + Duplicate, + Edit, + Error, + Export, + Help, + Import, + InfoSign, + Lightbulb, + Play, + Plus, + Redo, + Refresh, + Share, + Tick, + TickCircle, + Trash, + Undo, + Virus, +}; + +export const IconSvgPaths20 = { Cog: Cog20, Document: Document20 };