Parcel: Removes ids from inline-svgs in pug

Created on 27 Dec 2018  路  15Comments  路  Source: parcel-bundler/parcel

馃悰 bug report

馃帥 Configuration (.babelrc, package.json, cli command)

{
  "devDependencies": {
    "autoprefixer": "^9.4.3",
    "parcel-bundler": "^1.10.3",
    "parcel-plugin-purgecss": "^2.1.0",
    "parcel-plugin-sitemap": "^2.0.1",
    "parcel-plugin-sw-precache": "^1.0.3",
    "pug": "^2.0.3",
    "stylus": "^0.54.5"
  }
}

馃 Expected Behavior

Should not remove ids from svg when building pug files for prod; not dev.

EDIT: Works as supposed when --no-minify-flag is enabled?

馃槸 Current Behavior

Removes ids from svg when building pug files. But only svg.

PS. Only tried it with inline-svgs

馃實 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.11.0 |
| Node | 11.3.0 |
| Yarn | 1.12.3 |
| Operating System | 4.19.12-2-MANJARO |

Bug

Most helpful comment

@Mobilpadde
Add a .htmlnanorc file with

{
    "minifySvg": {
        "plugins": [
            { "cleanupIDs": false }
        ]
    } 
}

All 15 comments

Thanks for the report!

I've spent some time debugging, I think the issue is that htmlnano strips away the id from svg when minifying. Here is the relevant code in parcel. If we log asset.ast before and after the line, we could see the difference.

Here is a minimal example that isolates htmlnano.

Oh, thanks! :+1: Nice find!

Do you by any chance know a fix? :smiley_cat:

@Mobilpadde
Add a .htmlnanorc file with

{
    "minifySvg": {
        "plugins": [
            { "cleanupIDs": false }
        ]
    } 
}

Thanks a ton, @mischnic! :dancer: Works like a charm :gem:

This is really weird to track down (i had it happening for me from Vue svg files).

If we're talking good defaults (which is the point of parcel?) I feel this should not be the default for inlined svgs.

If we're talking good defaults (which is the point of parcel?) I feel this should not be the default for inlined svgs.

Might be good to open a PR in htmlnano for this.
The maintainer of htmlnano has been very open to improvements of the defaults in the past.

Adding a .htmlnanorc file to skip svg inline minification works.

{
    "minifySvg": false
}

If it appears that your .htmlnanorc file is being ignored, run Parcel with the --no-cache option.

This htmlnano package is breaking html-embedded SVG in various ways (changing styles/attributes, etc.). This doesn't seem like something that should be enabled by default.

Or maybe switch to another html minimizer? Surely there are others that are more robust?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

If it appears that your .htmlnanorc file is being ignored, run Parcel with the --no-cache option.

or just delete the ".cache" folder before building.

I deleted .parcel-cache and have --no-cache in both parcel serve and parcel build commands. Here's my .htmlnanorc 馃憞

{
    "removeUnusedCss": false,
    "minifySvg": false
}

But still, IDs are being stripped from inlined SVGs. 馃槙 It would be great if @lustoykov or @Mobilpadde could re-open the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

algebraic-brain picture algebraic-brain  路  3Comments

medhatdawoud picture medhatdawoud  路  3Comments

mnn picture mnn  路  3Comments

davidnagli picture davidnagli  路  3Comments

davidnagli picture davidnagli  路  3Comments