rollup-plugin-purge-icons

raw JSON →
0.10.0 verified Mon Apr 27 auth: no javascript

Rollup plugin for PurgeIcons, a tool that removes unused icon imports from icon libraries (e.g., Material Design, Font Awesome) to reduce bundle size. Version 0.10.0 is current stable; maintained by Anthony Fu. It works by analyzing your source code for used icon names and tree-shaking the rest. Key differentiators: automatic detection of icon usage, supports multiple icon sets, and integrates as a rollup plugin with zero configuration options needed in many cases. Requires @purge-icons/core and @purge-icons/generated as peer dependencies.

error Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
cause Trying to require() an ESM-only package in a CommonJS context.
fix
Use import syntax or set type: 'module' in package.json.
error Module not found: Can't resolve '@purge-icons/generated' in '/path/to/project'
cause @purge-icons/generated is not installed.
fix
Run npm install @purge-icons/generated --save-dev
error ReferenceError: exports is not defined in ES module scope
cause Using module.exports in an ES module file.
fix
Switch to export default or named exports syntax.
gotcha Import '@purge-icons/generated' must be in the entry file after the plugin is applied
fix Ensure the import is present in your entry file and not tree-shaken away.
breaking The plugin is ESM-only; require() will fail
fix Use import syntax. If you need CommonJS, consider using dynamic import() or transpile.
deprecated Node 12 support may be removed in future versions
fix Upgrade to Node >=14 for future compatibility.
gotcha The plugin does not automatically install @purge-icons/core and @purge-icons/generated
fix Install them as devDependencies: npm i @purge-icons/core @purge-icons/generated -D
npm install rollup-plugin-purge-icons
yarn add rollup-plugin-purge-icons
pnpm add rollup-plugin-purge-icons

Minimal rollup config using PurgeIcons plugin with default options.

import PurgeIcons from 'rollup-plugin-purge-icons';
import '@purge-icons/generated';

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'esm'
  },
  plugins: [
    PurgeIcons()
  ]
};