trunk-rs / trunk

Build, bundle & ship your Rust WASM application to the web.
https://trunkrs.dev/
Apache License 2.0
3.53k stars 255 forks source link

Minify assets for --release builds #7

Open thedodd opened 4 years ago

thedodd commented 4 years ago

This primarily applies to:

svenstaro commented 4 years ago

How about also optimizing PNGs?

thedodd commented 4 years ago

Sounds good to me. I’ll add it to the list above. Any ideas on libraries/algorithms we can use to accomplish this? I can’t say I’ve done much PNG optimization, I’d have to do some research on it.

thedodd commented 4 years ago

We can add a new pipeline handler which handles PNGs specifically and does optimization as part of the pipeline.

svenstaro commented 4 years ago

Seems like oxipng is absolutely perfect for this task.

MartinKavik commented 4 years ago

We need to minify also Rust/WASM. For instance, the difference in *.wasm file size between wasm-pack and Trunk for one my Seed app is ~700 KB in release mode. This minification is related to https://github.com/thedodd/trunk/issues/5 because we would need to use wasm-opt.

thedodd commented 4 years ago

@MartinKavik agreed. Release mode still makes a big difference, however there is no wasm-opt integration quite yet. We definitely need to get that added in.

mpfaff commented 2 years ago

How about minifying the generated JavaScript?

Carlrs commented 2 years ago

Tried implementing this, but the JS minifiers I found on crates.io had problems - one broke wasm-bindgen generated JavaScript and the other couldn't parse it properly, but the author seems fairly active on github so I created an issue on his parser.

Will create pull request for CSS and HTML, but JS will have to wait and I feel that's the biggest bit.

zstewar1 commented 11 months ago

What is the state of JS minifiers in trunk 18? The documentation on the website says that <script data-trunk ... copies scripts as-is. However I'm currently testing a project that uses hljs from an already minified bundle, which works in dev, but when I build it in prod, it becomes broken. The public name (hljs) gets minified away and one of the methods doesn't seem to exist, so code that depends on it just crashes.

ctron commented 11 months ago

Trunk 0.18.0 adds minification of css and html too. If you find an issue I would ask you to raise a new issue, so that we can track it. At best, having a reproducer would be helpful.