trunk icon indicating copy to clipboard operation
trunk copied to clipboard

Document minification backends

Open hsn10 opened this issue 1 year ago • 6 comments

Document here what minification backends are used since minification breaks things. I would like to know what software to avoid.

https://trunkrs.dev/assets/#minification

hsn10 avatar Jun 12 '24 07:06 hsn10

It's basically:

  • HTML: https://github.com/trunk-rs/trunk/blob/c160ed3ff7c98a94ab00f14acbbd198268a92525/Cargo.toml#L45
  • JS: https://github.com/trunk-rs/trunk/blob/c160ed3ff7c98a94ab00f14acbbd198268a92525/Cargo.toml#L46
  • CSS: https://github.com/trunk-rs/trunk/blob/c160ed3ff7c98a94ab00f14acbbd198268a92525/Cargo.toml#L78

HTML is based on lighteningcss and and minify-js.

ctron avatar Jun 12 '24 07:06 ctron

I believe lightningcss is solid because its used by parcel. Probably minify-js is to blame for failed minification.

hsn10 avatar Jun 14 '24 17:06 hsn10

That might be the case. I noticed that minify-js version 0.6.0 did break stuff. That's why we (like others) stick to 0.5. Maybe there's a better alternative.

ctron avatar Jun 17 '24 06:06 ctron

rust based turbopack, rspack and parcel are using swc as backend. deno is using spack from swc. https://swc.rs sems to be standard for rust based JS build tools.

processing JS have several stages such as: transpiling, bundling, tree shaking, minimize, polyfill.

Usually classic minimizing is safe operation - remove whitespace and comments, rename local variables to shorter names.

JS Minimizers often do also tree shaking and its risky operation - even tools years in production like google closure compiler - https://mvnrepository.com/artifact/com.google.javascript/closure-compiler are generating wrong code sometimes. Some build tools like esbuild can disable tree shaking separately from minimization.

In reality you can never be sure that these tools will deliver working JS code, its too complex operation combined with bugs in browsers. You can only test final result on few browsers. JS developers simply trust their tool brand: "for example babel for transpiling/polyfiling".

hsn10 avatar Jun 17 '24 14:06 hsn10

You seem to be the expert :) … any chance you can help out. IIRC the locations where minification is triggered should be pretty central/focused.

ctron avatar Jun 17 '24 15:06 ctron

I decided to go with wasm-pack + standard proven JS toolchain. wasm-opt doesn't do enough to justify risking another tool which can have bugs and generate wrong code.

I believe its ideal approach. wasm-pack plugin for JS tool and you are done.

hsn10 avatar Jun 19 '24 19:06 hsn10