Parcel: 馃檵 Make htmlnano configurable for production builds

Created on 29 Dec 2017  路  14Comments  路  Source: parcel-bundler/parcel

馃 Expected Behavior

To be able to pass options to htmlnano. Just like https://github.com/parcel-bundler/parcel/issues/347 did.

{
    minifySvg: false
}

馃槸 Current Behavior

Not able to pass any options.

馃拋 Possible Solution

馃敠 Context

My SVG file written in HTML is already optimized by svgo (but not to remove viewBox).
Using production build on parcel removes viewBox from SVGs.

Good First Issue Help Wanted Feature

Most helpful comment

@jaydickinson Remove the comma after false.
This worked for me!

{
  minifySvg: false
}

All 14 comments

There doesn't appear to be a standard config file for htmlnano

@thejameskyle if htmlnano takes an options object in its constructor, we could use that as the configuration file pattern?

We've been following this pattern for supported file names when a standard one isn't available: .htmlnanorc, .htmlnanorc.js.

@devongovett Thank you!! You saved my life:)

Hi,

Please can you share an example of how to ensure viewbox doesn't get removed?

I too am incurring the same issue as @gurmukhp, any solution?

@gurmukhp @albertorestifo

I think you can change svgo's config by creating a .svgo.yml file in the folder where parcel runs. I think it would be:

plugins:
  - removeViewBox: false

Context: https://github.com/svg/svgo/issues/707#issuecomment-349844367

Just create .htmlnanorc file in the root folder of the project and write:

{
  minifySvg: false,
}

It will save viewbox attr.

Doesn't work? anyone actually have a solution that works for this really frustrating just want to turn off the viewbox on minify...

tried creating the .htmlnanorc and adding
{ minifySvg: false, }

but nothing changes?

Followup to @jaydickinson comment: adding that code to my .htmlnanorc does work for me now. But I can't seem to enable/disable plugins this way.. As far as my debugging goes, SVGO does receive the configuration correctly, but it still seems to strip the viewBox

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

@jaydickinson Remove the comma after false.
This worked for me!

{
  minifySvg: false
}

@jaydickinson I had the exact same problem. What solved it for me was to rm -rf .cache and then rebuilding.

Thank you @hesselbom. Can't believe I didn't try that earlier.

When using parcel, to see the effect of adding .htmlnanorc.js you need to remove the .cache directory and do a full rebuild.
My .htmlnanorc.js is as follows:

module.exports = {
  "minifySvg": false
}

I confirmed that it was loaded by doing a console.log() in this .js file, and this only appeared after deleting the .cache and also that's when my SVG appeared correctly.

Was this page helpful?
0 / 5 - 0 ratings