Skip to content

Conversation

@t3rminus
Copy link
Contributor

@t3rminus t3rminus commented Jan 20, 2026

This PR splits up the icons into separate files in the ESM version of the build to allow for efficient tree-shaking when creating application bundles. Unused icons will be pruned from the final bundle dramatically reducing file size and loading time.

Before:
./node_modules/@raresail/react-ionicons/dist/esm/index.js (1.11 MB)

After:
./static/chunks/*.js (Count: 289)
Total size: 440.2 KB

@RaresAil RaresAil requested review from RaresAil and Copilot January 21, 2026 06:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restructures the build output to enable ESM tree-shaking by splitting individual icon components into separate files, reducing bundle sizes from 1.11 MB to 440.2 KB when only specific icons are imported.

Changes:

  • Modified Rollup configuration to generate separate files for each icon in the ESM build
  • Added post-build processing to conditionally re-add strokeWidth parameter only to icons that use it
  • Updated package.json with sideEffects field to support tree-shaking optimization

Reviewed changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated 3 comments.

File Description
rollup.config.js Reconfigured ESM output to use multiple entry points (one per icon file) instead of a single bundle
post-build-icons.js Added logic to selectively restore strokeWidth parameter to icon components that reference it
templates/svg.js Removed strokeWidth from default function parameters (restored conditionally in post-build)
package.json Added glob dependency, sideEffects configuration, and changed yarn to npm in build script

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

rollup.config.js Outdated
Comment on lines 44 to 47
// file, so e.g. src/nested/foo.js becomes nested/foo
path.relative('src', file.slice(0, file.length - path.extname(file).length)),
// This expands the relative paths to absolute paths, so e.g.
// src/nested/foo becomes /project/src/nested/foo.js
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment example references '.js' files but the actual glob pattern matches '.tsx' files. Update the comment to use '.tsx' in the example (e.g., 'src/nested/foo.tsx becomes nested/foo') for consistency.

Suggested change
// file, so e.g. src/nested/foo.js becomes nested/foo
path.relative('src', file.slice(0, file.length - path.extname(file).length)),
// This expands the relative paths to absolute paths, so e.g.
// src/nested/foo becomes /project/src/nested/foo.js
// file, so e.g. src/nested/foo.tsx becomes nested/foo
path.relative('src', file.slice(0, file.length - path.extname(file).length)),
// This expands the relative paths to absolute paths, so e.g.
// src/nested/foo becomes /project/src/nested/foo.tsx

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output file (src/nested/foo -> /project/src/nested/foo.js) is correctly js, as the compiled output file type will be js
The input line (src/nested/foo.js) has been resolved so it reads src/nested/foo.tsx

rollup.config.js Outdated
Comment on lines 44 to 47
// file, so e.g. src/nested/foo.js becomes nested/foo
path.relative('src', file.slice(0, file.length - path.extname(file).length)),
// This expands the relative paths to absolute paths, so e.g.
// src/nested/foo becomes /project/src/nested/foo.js
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment example shows the transformation to '.js' but the actual files being processed are '.tsx'. Update the comment to reflect '.tsx' in the example for accuracy.

Suggested change
// file, so e.g. src/nested/foo.js becomes nested/foo
path.relative('src', file.slice(0, file.length - path.extname(file).length)),
// This expands the relative paths to absolute paths, so e.g.
// src/nested/foo becomes /project/src/nested/foo.js
// file, so e.g. src/nested/foo.tsx becomes nested/foo
path.relative('src', file.slice(0, file.length - path.extname(file).length)),
// This expands the relative paths to absolute paths, so e.g.
// src/nested/foo becomes /project/src/nested/foo.tsx

Copilot uses AI. Check for mistakes.
package.json Outdated
"scripts": {
"build:icons": "rimraf ./src/icons && svgr ./src/svg && node post-build-icons.js",
"build": "rimraf ./dist && yarn run build:icons && rollup -c --bundleConfigAsCjs",
"build": "rimraf ./dist && npm run build:icons && rollup -c --bundleConfigAsCjs",
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build script was changed from 'yarn run' to 'npm run', but other scripts in the repository may still use yarn. This creates inconsistency in the build tooling. Consider using a consistent package manager throughout all scripts or document the reason for this change.

Suggested change
"build": "rimraf ./dist && npm run build:icons && rollup -c --bundleConfigAsCjs",
"build": "rimraf ./dist && yarn run build:icons && rollup -c --bundleConfigAsCjs",

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant