Make @tabler/icons-react fully tree-shakeable#1551
Open
liamdon wants to merge 2 commits into
Open
Conversation
Ship a full `exports` map with per-icon deep imports, dual ESM/CJS output that preserves one module per icon, per-icon type declarations, and a working dynamic-import entry. The icon set and component API are unchanged. - Named imports from the root tree-shake in modern bundlers; deep imports (`@tabler/icons-react/IconArrowLeft`) guarantee a one-icon load in any bundler. - `@tabler/icons-react/dynamic` exposes a kebab-case-keyed loader map for runtime lazy-loading. - The `icons`/`iconsList` namespace re-exports were removed from the package root (they defeated tree-shaking); the icon-name list now lives at the `@tabler/icons-react/icons-list` subpath.
The `accessible` source SVG draws the inner dot as a `<path>` and uses normalized arc notation for the outer ring, but the inline snapshot still expected the older `<circle>` form. Regenerate it so the test matches the icon source. Pre-existing mismatch, independent of the tree-shaking change.
|
@liamdon is attempting to deploy a commit to the Tabler Team on Vercel. A member of the Team first needs to authorize it. |
|
✅ All icons are valid! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: these changes are currently published under tabler-icons-react-esm. If this PR is accepted I will deprecate the separate package and add a README note pointing back to this repo.
Motivation
Reliable tree-shaking and subpath imports for
@tabler/icons-reactare among the most-requested improvements to this package. An app importing a handful of icons shouldn't pull the whole set into its bundle, and people have repeatedly asked to be able to import a single icon by subpath or by dynamic import, and to improve bundling performance in dev mode:This PR reworks the package's build to address all of these complaints, while keeping the icon set and component API 100% unchanged and maintaining CJS compatibility; existing
import { IconArrowLeft } from '@tabler/icons-react'code keeps working with no changes.Changes
The package now ships:
exportsmap enabling per-icon subpath imports (@tabler/icons-react/IconArrowLeft).preserveModules) instead of a single concatenated barrel, so bundlers can drop what you don't use.No changes to the icons themselves, the component implementation, or the public component API.
Three ways to import
1. Named import (recommended for app code) now tree-shakes reliably:
2. Deep / subpath import guarantees one-icon load in any bundler without analysis:
3. Dynamic import lazy-loads at runtime; native deep dynamic import, or a kebab-case-keyed loader map for names coming from a CMS/config:
Tree-shaking & bundler compatibility
Because each icon is its own ES module and the package is marked
sideEffects: false, named imports tree-shake out of the box in:experimental.optimizePackageImports: ['@tabler/icons-react']For older toolchains, or to guarantee a minimal bundle regardless of bundler analysis, the subpath import form above always loads exactly one icon.
One behavioral note (backward compatibility)
The only removal: the
icons/iconsListnamespace re-exports were dropped from the package root, because re-exporting every icon from the entry point defeats tree-shaking. The icon-name list now lives at a dedicated subpath:Verification
pnpm --filter @tabler/icons-react buildsucceeds (ESM + CJS + types + dynamic maps).pnpm --filter @tabler/icons-react test— 9/9 pass, no type errors.