sveltejs / sapper

The next small thing in web development, powered by Svelte
https://sapper.svelte.dev
MIT License
6.99k stars 433 forks source link

Allow access to html minify config #348

Open aubergene opened 6 years ago

aubergene commented 6 years ago

Currently the HTML minify config is hard coded. I need to use SSIs in my template, so I'm using a fork. It would be good to be able to change the config with a Sapper project, but I wasn't sure the best way to enable this.

hdoro commented 4 years ago

Same here! Besides @aubergene 's use for comments, which is impossible in Sapper's current state, WhatsApp link sharing only understands og:image if its meta tag is formatted with commas:

<!-- This works, WhatsApp reads into the comments -->
<meta property=og:image content=https://biptt-dev.netlify.com/ogImageSquare.png >
<!-- <meta
  property="og:image"
  content="https://biptt-dev.netlify.com/ogImageSquare.png"
/> -->

<!-- This doesn't work (line below unchanged) -->
<meta property=og:image content=https://biptt-dev.netlify.com/ogImageSquare.png >

<!-- Now it works (has commas) -->
<meta property="og:image" content="https://biptt-dev.netlify.com/ogImageSquare.png" >

See for yourselves with the minified version and the formatted version (grab the URLs and share them on WhatsApp, the image won't show up).

This is very grave and might be hurting tons of websites' conversions as social sharing is a big aspect of driving people to the site.

The quick-fix should be easy: just set removeAttributeQuotes: false in html-minifier's configuration! I will make a PR tomorrow if I have the time 😉

As to a more long-term solution, I'd say we follow Julian's idea of exposing the html-minifier configuration :)

hmaesta commented 3 years ago

A really non-recommended workaround for the ones who really needs this...

  1. Edit node_modules/sapper/dist/minify_html.js to your taste
  2. Run yarn export

Again: not recommended. Do by your own risk.

dan-peterson commented 3 years ago

Another option if you're between a rock and a hard place is to monkey patch it on post install:

"postinstall": "mv src/minify_html.js node_modules/sapper/dist/minify_html.js"