headstart icon indicating copy to clipboard operation
headstart copied to clipboard

SVG optimization

Open nunodotferreira opened this issue 11 years ago • 12 comments

Hi again, :)

is there a way of not optimize SVG files? I'm having some problems with that, and want not to have that optimized when in production!

thanks again

nunodotferreira avatar Oct 24 '14 10:10 nunodotferreira

hmm, I guess you can put them in (for example) assets/svg and just have them moved over. Everything from assets/images will get optimized otherwise.

flovan avatar Oct 24 '14 12:10 flovan

@nunodotferreira Did my suggestion help you out?

flovan avatar Oct 30 '14 14:10 flovan

that's what i'm been doing, but it's a manual thing!!!

nunodotferreira avatar Oct 30 '14 14:10 nunodotferreira

What kind of problems are you having exactly, if I may ask? It might be related to a module bug, so then I can go over and ask for a fix. And otherwise I'll see if I can fit in another optional setting.

flovan avatar Oct 30 '14 14:10 flovan

Well, because i'm styling SVG and using CSS to change color of the SVG objects, when i'm in --serve mode all works fine, because the SVG are not optimized, but when i create a production 'code' the optimization removes some SVG parameters that i'm using, and the CSS doesn't work… :( that's why I'm having problems...

nunodotferreira avatar Oct 30 '14 14:10 nunodotferreira

Yeah that definitely shouldn't happen. Any specific things that get stripped? Like class names, or maybe your paths get merged? The more I know, the easier for me to find a solution for this!

flovan avatar Oct 30 '14 15:10 flovan

Hi Flovan, well the optimization changes the name of the objects.

Hi have this object code before optimization:

<clipPath clipPathUnits="userSpaceOnUse" id="clipPath5093"> </clipPath>

but after optimization:

<clipPath></clipPath>

this alter's my css style.

nunodotferreira avatar Oct 31 '14 11:10 nunodotferreira

There is a solution for this, but a bit of work is required to find out the specific configurations that are causing this. If you feel like helping out that would be much appreciated, otherwise I'll do it sometime in the future.

Note: Required changes below include the updates that the next Headstart update will bring

First off, open up gulpfile.js at the imagemin procedure, and expand the the options object as following:

gulp.task('images', function (cb) {

    /**/

    return gulp.src([
            'assets/images/**/*',
            '!_*'
        ])
        /**/
        .pipe(plugins.if(isProduction, plugins.imagemin({
            optimizationLevel: 3,
            progressive: true,
            interlaced: true,
            svgoPlugins: [ /* READ ON */ ]
        })))
        /**/
    ;
});

Next, try to find out which SVGO plugin(s) needs to be disabled by using the svgoPlugins Array:

svgoPlugins: [
    { nameOfThePluginWithoutExtenstion: false },
    ...
]

A list of plugins can be found in the SVGO repository.


I can expose the plugins through the config file, but some research is needed first to make sure that this actually works. Otherwise, SVGO will have to be disabled and replaced by a different optimiser, or SVG optimisations will need a setting to be entirely disabled.

flovan avatar Oct 31 '14 13:10 flovan

Hi,

i do this test and i'll see if i can find the plugin that breaks my style… :)

good work

nunodotferreira avatar Oct 31 '14 15:10 nunodotferreira

:+1:

flovan avatar Oct 31 '14 15:10 flovan

@nunodotferreira I will add in the followng config option to disable SVG optimisation entirely for V2 (exact name might change):

Either don't optimize anything at all:

{
    [...]
    disableSVGOptimization: true
    [...]
}

or for specific files:

{
    [...]
    disableSVGOptimization: [
       "aFileName.svg",
       "anotherCustomSVG.svg",
       [...]
    ]
    [...]
}

flovan avatar Mar 13 '15 08:03 flovan

that's fine, i'm using this in some cases, but if .svg files are complex the optimization fails and then i used the original file. So both options are fine. Thanks

nunodotferreira avatar Mar 13 '15 09:03 nunodotferreira