Webpack 2.x tree shaking SVG icons with svg-sprite-loader

Viewed 557

I'm bundling my project using webpack 2.x and most of the tree shaking parts work fine except that I have all svg images in exported svg file even if I'm not using them.

SVG icons icons.js

export { default as icon1 } from "./svg/icon1.svg";
export { default as icon2 } from "./svg/icon2.svg";

And then in the svg icons index.js

import { icon1 } from "./icons";
console.log('Use icon1', icon1);
export default {};

Webpack svg-sprite-loader plugin configuration:

{
    test: /\.svg$/,
    use: [
        {
            loader: 'svg-sprite-loader',
            options: {
                extract: true,
            },
        }
    ],
}

The result is the bundle.js and sprite.svg. The sprite.svg contains both icon1 and icon2 but I'd expect to have just icon1. How can I make this svg shaking work?

0 Answers
Related