cascornelissen / svg-spritemap-webpack-plugin

SVG spritemap plugin for webpack
MIT License
210 stars 51 forks source link

doesnt work with Imagemin webpack plugin #160

Closed saltnpixels closed 3 years ago

saltnpixels commented 3 years ago

I am using a scripts build so I created a webpack.config file and extended the plugins and added this plugin in the hopes of having it generate the sprite.

const defaultConfig = require('scripts/config/webpack.config');
const SVGSpritemapPlugin = require('svg-spritemap-webpack-plugin');

defaultConfig.plugins.push(new SVGSpritemapPlugin('assets/svg/*.svg', { output: {filename: 'svg/symbol-defs.svg'}}))
module.exports = {
    ...defaultConfig,
};

This creates the file, but its empty. Any ideas why?

saltnpixels commented 3 years ago

The scripts I am hooking into: https://github.com/10up/10up-scripts/blob/develop/config/webpack.config.js

saltnpixels commented 3 years ago

Interestingly i think it works on watch but not build...

saltnpixels commented 3 years ago

After palying around I found that its the imagemin plugin... Its ruining the output... Anything I can do? I have tried putting this plugin before and after imagemin. Nothing works :/

cascornelissen commented 3 years ago

I don't have much experience with the 10up scripts or the imagemin-webpack-plugin but IMO the most logical thing to do would be to exclude the generated spritemap from being minified by imagemin by using the test option for that plugin.

This plugin already minifies the SVG using svgo so there's no need to let imagemin minify the file again.

cascornelissen commented 3 years ago

Closing this due to inactivity and it has a solution, feel free to comment if anything pops up ❤️