thomashoneyman / purescript-halogen-realworld

Exemplary real world application built with PureScript + Halogen
https://thomashoneyman.com/guides/real-world-halogen
MIT License
792 stars 86 forks source link

Migrate to PureScript 0.15 #112

Closed thomashoneyman closed 2 years ago

thomashoneyman commented 2 years ago

This pull request migrates Real World Halogen from PureScript 0.14 to 0.15 and from Halogen 6 to 7.

The biggest update to the compiler in PureScript 0.15 is the switch from CommonJS to ES modules. Among other benefits, the new output results in up to 25% smaller bundles (Real World Halogen dropped 100kb, from 600kb to 500kb 🎉). It also means that we no longer need to use zephyr, so that has been dropped from this project. Learn more:

Halogen 7 is an intentionally tiny release that mostly provides compatibility with PureScript 0.15. It has no changes that affected Real World Halogen. Still, it may have changes that affect you, so it's worth reading that migration guide too:

And that's about it! Upgrading to the latest compiler and Halogen release is pretty painless.

paulyoung commented 2 years ago

Zephyr stopped working in my project after I upgraded to 0.15 and I came here to see what you might be doing.

Can you explain why Zephyr is no longer needed, or are you just satisfied the the bundle is small enough to remove it? Thanks!

paulyoung commented 2 years ago

FWIW, my build started failing with errors like this:

✘ [ERROR] Could not resolve "./foreign.js"

    dce-output/Effect/index.js:3:23:
      3 │ var $foreign = require("./foreign.js");
paulyoung commented 2 years ago

According to this, it seems like tools like webpack should now be able to do DCE. I'm also using esbuild so curious how that works out.

https://discord.com/channels/864614189094928394/872650895744176188/983717748666413108

thomashoneyman commented 2 years ago

JS bundlers had a hard time performing dead code elimination on the CommonJS output of the PureScript compiler prior to 0.15. For that reason, I relied on Zephyr to perform DCE on the PureScript code, and then bundled the result.

However, the PureScript 0.15 compiler produces ES modules as output, with purity annotations, which greatly helps bundlers like webpack and esbuild along. Bundling the output of the PureScript 0.15 compiler is typically about 30% smaller than bundling the output of PureScript 0.14 compiled to corefn and then run through Zephyr.

The end result: Zephyr isn't needed anymore. If you need any extra motivation, I don't believe there's a version of Zephyr that even works with the PureScript 0.15 compiler.