Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
How to remove unused SVG assets from webpack bundle while using custom SVG icons library

I have SVG Icon library which exports all the SVG images as modules like below

Icon Library

import React from 'react';
import Clock from './icons/clock.svg';
import Calender from './icons/calender.svg';

export const ClockIcon = Clock
export const CalenderIcon = Calender;

And I am using the library in application like below

Using Icon library in application

import React from 'react';
import { Button as MUIButton } from '@mui/material';
import './button.scss';
import { Icon } from '../Icons/Icon';
import { ClockIcon } from '../../../dist';

function Button(props: any) {
  const { label, ...rest } = props;
  return <>
    <Icon icon={ClockIcon} />
    <MUIButton {...rest}>{label}</MUIButton>
  </>;
}

export default Button;

When running webpack build inside the build both SVGs are present

Even though If I am using only Clock Icon Calender Icon also gets added to the bundle.

enter image description here


Is there any way to ensure only used assets are included in the bundle.

I don't want to directly import SVG Icons like below to achieve this

import ClockIcon from '../../../dist/icons/clock.svg';

In webpack there is a optimization parameter called usedExports which will ensure the unused exports are not getting included in the bundle. But the code only works for unused javascript code. Not for svg files.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda