jorgebucaran / superfine

Absolutely minimal view layer for building web interfaces
https://git.io/super
MIT License
1.56k stars 78 forks source link

Using Terser to minify #150

Closed Wildhoney closed 5 years ago

Wildhoney commented 5 years ago

FYI I've had a lot of luck with Switzerland in minifying JS modules that's still usable in the browser with Terser.

The way I go about it is to offer both side-by-side:

Have you thought about minification? Would you like me to try and implement it in Superfine?

jorgebucaran commented 5 years ago

@Wildhoney Do you mean swapping uglify-js to terser? What's the difference between them by the way?

Wildhoney commented 5 years ago

Well, UglifyJS is stuck in ES5 land, so in your build you're running it through rollup to then uglify where by using Terser directly there's no need to jump through those hoops as it recognises ESx code.

In my case all I have is a JS file that I run via node: https://github.com/Wildhoney/Switzerland/blob/master/terser.config.js

Likewise your minified code doesn't run as type="module" as it needs a build step to process it, whereas the way I've set it up using Terser, it's still a valid ES module with minification applied.

With how I'm using Superfine I simply import it via CDN.

jorgebucaran commented 5 years ago

@Wildhoney Sounds excellent, but can it be done without a terser.config.js file?

mindplay-dk commented 5 years ago

@jorgebucaran it appears to have CLI compatibility with uglify, so it may just work as a drop-in replacement :-)

Wildhoney commented 5 years ago

Uglify takes a single entry file that has usually been preprocessed by Rollup/Webpack, whereas Terser minifies one file at a time. What I was looking for was a way to pass a glob expression as the entry files, and then specify an output directory where the file structure would be maintained.

I had zero luck with their CLI in trying to accomplish the above, which is why I opted to use their Node interface.

See: https://github.com/terser-js/terser/issues/75