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

html in ssr components are not minified #950

Open hgl opened 5 years ago

hgl commented 5 years ago

Describe the bug

  1. run npm run build
  2. open __sapper__/build/server/server.js
  3. search for create_ssr_component(($$result
  4. look at the unminifed html string

Information about your Sapper Installation:

Additional context I was looking at the source code of returned html in browser (npm run start, not dev version), and found the html were mostly unminified.

ghost commented 4 years ago

Jup, just came here after encountering the same unwished behaviour. I hope this can get addressed soon...

jeromebon commented 4 years ago

I don't think it's svelte issue. You can add an express midleware to minfy your html. Or if you use export there is external tools to do so. Is there any case where it's not enought?

ghost commented 4 years ago

@Mojeer0 Adding express middleware means that Express has to modify the source in memory, the source itself will not be changed from what I've heard. I know the few newlines aren't a huge drama, but I'm a perfectionist and it just seems off when I've minified everything else over rollup, but the production output of sapper contains unminified html. I'd appreciate some official guidance on how to achieve this.

glaeh commented 4 years ago

+1

benmccann commented 4 years ago

There's actually a helper method to minify html already: https://github.com/sveltejs/sapper/blob/f3e9fc48d281ff990458a4a537a50d59db105e37/src/api/utils/minify_html.ts#L3

glaeh commented 4 years ago

There's actually a helper method to minify html already:

https://github.com/sveltejs/sapper/blob/f3e9fc48d281ff990458a4a537a50d59db105e37/src/api/utils/minify_html.ts#L3

This appears to be used to minify the template.html file on build... I don't see any obvious way to use it to minify SSR output, unless I'm mistaken?

benmccann commented 4 years ago

I'm not saying there's an easy way to use that method as an end user today, but that an implementation of this feature could utilize that method

ghost commented 4 years ago

We might want to open an issue at svelte-preprocess instead. It can already transform svelte component html (it supports pug for example), so we could ask the maintainer to maybe add an option to minify it as well.