Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI flags to disable HTML/CSS/JS minification individually #7370

Closed
megaphonecolin opened this issue Nov 26, 2021 · 4 comments
Closed

CLI flags to disable HTML/CSS/JS minification individually #7370

megaphonecolin opened this issue Nov 26, 2021 · 4 comments

Comments

@megaphonecolin
Copy link

megaphonecolin commented Nov 26, 2021

馃檵 feature request

Add independent CLI flags to disable HTML/CSS/JS minification individually. Example:
--no-optimize-html
--no-optimize-css
--no-optimize-js

The following question contains a workaround, but the workaround is error prone (see my comment for an explanation of why).
#2561

馃敠 Context

  1. Minification sometimes breaks applications in subtle, difficult-to-diagnose ways. Developers do not always have the time or expertise to determine the exact cause of a failure caused by minification, and, therefore, opt to disable minification completely to ensure their application works correctly. However, opting out of ALL minification is often overkill. If CSS or HTML minification causes an application to fail, a developer might want to opt out of the offending minification only, while retaining the benefits of all other minification.

  2. Some developers prefer to keep their CSS or HTML source untouched and human readable, while still minifying JavaScript.

馃捇 Examples

@megaphonecolin megaphonecolin changed the title CLI flags to disable HTML/CSS/JS minification selectively CLI flags to disable HTML/CSS/JS minification individually Nov 26, 2021
@mischnic
Copy link
Member

With parcel 2, you can do use this parcelrc to remove all default html optimizers

{
	"extends": "@parcel/config-default",
	"optimizers": { "*.html": [] }
}

List of default optimizer plugins:

"optimizers": {
"data-url:*": ["...", "@parcel/optimizer-data-url"],
"*.css": ["@parcel/optimizer-cssnano"],
"*.{html,xhtml}": ["@parcel/optimizer-htmlnano"],
"*.{js,mjs,cjs}": ["@parcel/optimizer-terser"],
"*.svg": ["@parcel/optimizer-svgo"],
"*.{jpg,jpeg,png}": ["@parcel/optimizer-image"]
},

@megaphonecolin
Copy link
Author

Fantastic!! Just tested on our application (where HTML minification was causing failures). Works perfectly. Thanks for the lightning-quick response. This issue can be closed. I'll update my comment in question #2651 accordingly.

@hashimaziz1
Copy link

hashimaziz1 commented Jun 21, 2022

Thanks for this, Parcel's HTML minification was also causing noticeable bugs with my relatively small static site. Very worrying because I dread to think how much more damage would have been done if I'd been using it on a larger site.

@myklemykle
Copy link

I just tried this solution, to leave my index.html unchanged. But it doesn't quite work.

Html minification appears to be disabled in the file, but something else is still minimising the JS in the interior of <script> tags in the html file. This prevents the JSON config section of my index.html from being legible or easily hand-edited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants