6.0.3 • Published 1 month ago

postcss-svgo v6.0.3

Weekly downloads
8,277,317
License
MIT
Repository
github
Last release
1 month ago

postcss-svgo

Optimise inline SVG with PostCSS.

Install

With npm do:

npm install postcss-svgo --save

Example

Input

h1 {
    background: url('data:image/svg+xml;charset=utf-8,<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve"><circle cx="50" cy="50" r="40" fill="yellow" /></svg>');
}

h2 {
    background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgcj0iNDAiIGZpbGw9InllbGxvdyIgLz48IS0tdGVzdCBjb21tZW50LS0+PC9zdmc+');
}

Output

h1 {
    background: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40" fill="%23ff0"/></svg>');
}

h2 {
    background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxjaXJjbGUgY3g9IjUwIiBjeT0iNTAiIHI9IjQwIiBmaWxsPSIjZmYwIi8+PC9zdmc+');
}

API

svgo([options])

options

encode

Type: boolean Default: undefined

If true, it will encode URL-unsafe characters such as <, > and &; false will decode these characters, and undefined will neither encode nor decode the original input. Note that regardless of this setting, # will always be URL-encoded.

plugins

Optionally, you can customise the output by specifying the plugins option. You will need to provide the config in comma separated objects, like the example below. Note that you can either disable the plugin by setting it to false, or pass different options to change the default behaviour.

const postcss = require('postcss');
const svgo = require('postcss-svgo');

const opts = {
    plugins: [{
        name: 'preset-default',
        params: {
            overrides: {
                removeViewBox: false,
                removeComments: false,
                cleanupNumericValues: {
                    floatPrecision: 2
                }
            }
        }
    }]
};


postcss([ svgo(opts) ]).process(css).then((result) => {
    console.log(result.css)
});

You can view the full list of plugins here.

Usage

See the PostCSS documentation for examples for your environment.

Contributors

See CONTRIBUTORS.md.

License

MIT © Ben Briggs

cssnano-preset-defaultvuedragdropuploadimagescloud-archive-s3bb-chattzar-core@fundefund/funde_ckgql_din_mod@olivervorasai/slidercogoportutils@saaspe/componentsexpand-react-bridgesklif-ui-kitsklif-api@everything-registry/sub-chunk-2462@314oner_npm/universal-components-libraryp149-tabletest-popupssklif-ui@graines-digitales/nice-handsome-buttonemr-tabulator-tables@hproinformatica/functions@humanity.cash/types@hoaitt/ckeditor5-build-classic-mentionera-ckeditor5es-react-bridge@harsha-jalan/ckeditor5-custom-build@hazyflame/vue-jitsi-meet@greminder/bootstrap-material-designsearch-list-reactsdk-fundmentalsex-ikon-components-librarysearch-input-reactfhir2sequelcomponent@infinitebrahmanuniverse/nolb-postcss-s@ikon-x/ckeditor5-custom-build-for-irrosoft@fovea/cli@gotoeasy/csjs@gen3/ui-componenteasyplayer-my@fabwcie/ckeditor5-preview@img-arena/img-ui-mui-theme@img-arena/ui-core@kommunicate/kommunicate-chatbot-plugin@kristoffertonning/vue-laravel-errors@pumpn/cssnano-preset-default@purnasatria/directus-extension-document-interfaceuxun-cssnanovformlmqverify-img-codejesusdemo@refactorpro/pixi-virtual-joystickvite-plugin-svg-utilskafirchain-tetrisvue3-google-login-with-state@sak1sham/react-toc-highlightvue-compment@knooks/use-title@itayn-fireberry-org/itayn-test@itsridhopratama/taman-baca-masyarakatflowable-bpmn-modeler@juanzenn/ckeditor5-custom-build@juanaraneta/dept-central-lib-clientsobiratel@junvary/quasar-ui-qcascader@meysam213/react-leaflettingzi-vuepress@nlabs/lexgulpfile.js@mrdeff/bitrixcli@ngxvoice/ngx-voicelistnerwebpackdemo@skeetboothppq/component-library@silver0542/directus-extension-cma-components-editor@ozancakir/ckeditor5-build-inline-balloon@percent/percent-api-hooksvirtual-tour-guidevue-button-test1julien-easy-modal@qbs/bitrixclitype-libary@oriduk/ckeditor5-rebuild-musicanote@oriduk/ckeditor5-rebuild-oriduktohsaka888-use-breakpointhot-zone-vuetestujsk_custom_ckeditor5testapagarnish-uistock-ticker-react-widgetsticky-scroll-catchstories-react-bd@leiyulf/gantt-task-reactgenerator-bootstrap-boilerplate-template@mayuriachewad/pickupbiz-npm-packagetaman-baca-masyarakathantil-cssstyle-guide-mainsummerseatestlained-ckeditor5@zalastax/nolb-postcss-s
6.0.3

1 month ago

6.0.2

4 months ago

6.0.1

4 months ago

6.0.0

1 year ago

5.1.0

2 years ago

5.0.4

2 years ago

5.0.3

2 years ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.0.3

3 years ago

5.0.0-rc.2

3 years ago

5.0.0-rc.1

3 years ago

5.0.0-rc.0

3 years ago

4.0.2

5 years ago

4.0.1

6 years ago

4.0.0

6 years ago

4.0.0-rc.2

7 years ago

4.0.0-rc.0

7 years ago

2.1.6

7 years ago

2.1.5

8 years ago

2.1.4

8 years ago

2.1.3

8 years ago

2.1.2

8 years ago

2.1.1

8 years ago

2.1.0

8 years ago

2.0.4

9 years ago

2.0.3

9 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.1.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago