Skip to content

Commit 90b04f8

Browse files
committed
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]: palantir/blueprint#2193
1 parent 694b064 commit 90b04f8

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

config/webpack.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ module.exports = function (webpackEnv) {
586586
].filter(Boolean),
587587
},
588588
plugins: [
589+
// https://github.com/palantir/blueprint/issues/2193
590+
new webpack.NormalModuleReplacementPlugin(
591+
/.*\/@blueprintjs\/icons\/lib\/esm\/iconSvgPaths.*/,
592+
path.resolve(__dirname, "../src/blueprintjs-icons.js")),
589593
new CopyPlugin({
590594
patterns: [
591595
{

src/blueprintjs-icons.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2022 The Pybricks Authors
3+
4+
// HACK: Prevent webpack from picking up all icons.
5+
// https://github.com/palantir/blueprint/issues/2193
6+
7+
import {
8+
Add,
9+
Archive,
10+
Blank,
11+
Chat,
12+
ChevronDown,
13+
ChevronRight,
14+
Clipboard,
15+
Code,
16+
Cog,
17+
Cross,
18+
Disable,
19+
Document,
20+
Download,
21+
Duplicate,
22+
Edit,
23+
Error,
24+
Export,
25+
Help,
26+
Import,
27+
InfoSign,
28+
Lightbulb,
29+
Play,
30+
Plus,
31+
Redo,
32+
Refresh,
33+
Share,
34+
Tick,
35+
TickCircle,
36+
Trash,
37+
Undo,
38+
Virus,
39+
} from '@blueprintjs/icons/lib/esm/generated/16px/paths';
40+
import {
41+
Cog as Cog20,
42+
Document as Document20,
43+
} from '@blueprintjs/icons/lib/esm/generated/20px/paths';
44+
import { pascalCase } from 'change-case';
45+
46+
export function iconNameToPathsRecordKey(name) {
47+
return pascalCase(name);
48+
}
49+
50+
export const IconSvgPaths16 = {
51+
Add,
52+
Archive,
53+
Blank,
54+
Chat,
55+
ChevronDown,
56+
ChevronRight,
57+
Clipboard,
58+
Code,
59+
Cog,
60+
Cross,
61+
Disable,
62+
Document,
63+
Download,
64+
Duplicate,
65+
Edit,
66+
Error,
67+
Export,
68+
Help,
69+
Import,
70+
InfoSign,
71+
Lightbulb,
72+
Play,
73+
Plus,
74+
Redo,
75+
Refresh,
76+
Share,
77+
Tick,
78+
TickCircle,
79+
Trash,
80+
Undo,
81+
Virus,
82+
};
83+
84+
export const IconSvgPaths20 = { Cog: Cog20, Document: Document20 };

0 commit comments

Comments
 (0)