Open nCubed opened 3 years ago
What type of attributes exactly do you mean?
html-minifier(-terser) only minifies the code but does not cover such prod / dev differences since this has not much to do with the general minification.
To be honest I never had this use case in more than 11 years.
I guess you have a build setup which uses webpack or something else. So there you can do the needed replacements.
There are already plugins for webpack and babel which do this:
https://www.google.com/search?q=webpack+html+remove+attributes+plugin https://stackoverflow.com/questions/43934210/remove-html-attribute-in-production-build
We're not using webpack. The attributes are used during language translation; the localized files have the attributes removed, but the original non-localized files keep the attributes. I've put in a request to the package's repository to include the option to strip the attributes from the original files, but the maintainer(s) have not replied.
Was thinking maybe you could piggy-back on the current setting for removeEmptyAttributes
and include the option to pass in an array of attributes to remove as well.
Understood this is a weird edge-case. Thought I'd ask :)
I am fine in adding that option to do this, but I don't feel like removeEmptyAttributes
is the right place even to piggy-back it.
One way for you is to write a script to read the minified file and replace(remove) attributes may be with regex or whatever that works. or we can introduce a new option may be removeAttributes
which can take an array of attributes to be removed.
Obviously my preference would be the latter option of removeAttributes
🤩
We have a few attributes we use in dev, but are not needed in prod. Any chance a new setting could be created, allowing an array of attributes to be stripped from the minified html?