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
This commit is contained in:
David Lechner
2022-10-27 13:17:51 -05:00
committed by David Lechner
parent 694b064683
commit 90b04f85b3
2 changed files with 88 additions and 0 deletions
+4
View File
@@ -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: [
{
+84
View File
@@ -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 };