Rich-Harris / butternut

The fast, future-friendly minifier
https://butternut.now.sh
MIT License
1.17k stars 17 forks source link

prepack style computations at compile-time #39

Closed thisconnect closed 7 years ago

thisconnect commented 7 years ago

Hi @Rich-Harris

Is computations at compile-time in scope of butternut, or would you suggest to run prepack before butternut https://prepack.io/ ?

prepack example https://butternut.now.sh/?version=0.3.3&gist=ff2ce6ea73b6e86f055aefd3ceb3962f

Rich-Harris commented 7 years ago

Butternut will do 'constant folding' (live demo):

// input
console.log( 1 + 2 + 3 * 4 );

if ( "development" === "production" )
  console.log( "running in development mode" );
else
  console.log( "running in production mode" );

// output
console.log(15),console.log("running in production mode")

(though I've just spotted a bug with curly braces... will fix)

Beyond that, though, Prepack-style optimisations are definitely out of scope for a project like this. I think the recommended approach would be to use Prepack before a minifier — but with a great deal of care, since it doesn't yet have any guarantees it won't make your code larger or slower!

thisconnect commented 7 years ago

Good to know thanks @Rich-Harris !