question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parcel 2: SVGO Optimizer

See original GitHub issue

Create the @parcel/optimizer-svgo package. This should include an Optimizer plugin that compresses SVG images with SVGO.

This plugin should be included in @parcel/config-default for *.svg to optimize SVGs by default in production.

Configuration

Optional configuration should be done through a .svgorc file. We should include good default settings, but it should be possible to override them if needed. See here for a full list of options.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (17 by maintainers)

github_iconTop GitHub Comments

3reactions
elozevcommented, Sep 20, 2021

I found a workaround solution. Create a .parcelrc file at the root of the project. As contents put the following

{
  "extends": "@parcel/config-default",
  "transformers": {
    "url:*.svg": ["@parcel/transformer-svgo", "@parcel/transformer-raw"]
  },
  "optimizers": {
    "*.{png,jpg,jpeg,svg}": []
  },
}

That solved the issue for me. The command to build the project in my case is: "build": "parcel build *.html --no-cache".

1reaction
artdevgamecommented, Aug 7, 2021

To make SVG optimization work in Parcel I need to install @parcel/transformer-svgo and add the following to .parcelrc

{
  "extends": "@parcel/config-default",
  "transformers": {
    "url:*.svg": ["@parcel/transformer-svgo", "@parcel/transformer-raw"]
  }
}

I can’t seem to get this to work in my project, I’m using --public-url . CLI option, could that be making a difference?

The error I get is something like:

react-dom.development.js:11340 Uncaught DOMException: Failed to execute ‘createElement’ on ‘Document’: The tag name provided (‘/discord.d697f2b7.svg’) is not a valid name.

Looks like it’s relying on a url path, where I need it to start with ./

Read more comments on GitHub >

github_iconTop Results From Across the Web

SVG - Parcel
This uses SVGR to transform the SVG file into JSX. It also uses SVGO to optimize the SVG to reduce file size. This...
Read more >
@parcel/optimizer-svgo | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
@parcel/transformer-svgo NPM | npm.io
@parcel/transformer-svgo v2.0.0-nightly.1739. Install. Weekly downloads ... optimizers is an object map of globs to arrays of Parcel optimizer packages.
Read more >
parcel-optimizer-imagemin - npm package - Snyk
Parcel optimizer plugin to minify images seamlessly. For more information about how to use this package see README.
Read more >
Hah, I literally spent a day trying to use parcel to optimize a ...
on: Parcel 2 Beta 3 – improved build performance ... maybe do some image minification (svgo), compile using the latest sass module features...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found