Skip to content

Commit

Permalink
webpack: add hack to remove unused icons
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dlech committed Oct 27, 2022
1 parent 694b064 commit 90b04f8
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
84 changes: 84 additions & 0 deletions src/blueprintjs-icons.js
Original file line number Diff line number Diff line change
@@ -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 };

0 comments on commit 90b04f8

Please sign in to comment.