purs-loader
purs-loader copied to clipboard
Integrate zephyr dead code elimination
Hi,
I wanted to see how much effect zephyr
dead code elimination would have on a production build. It shaved of ~ 80 kb (gzipped) / 535 kb (zipped) / 50+ % (if I'm not mistaken).
So I'm sold on trying to integrate it in the build. Here is a draft PR, that shows the current integration.
If you want to give it a try, there is a pre-compiled branch and you can use it like this in package.json
:
"purs-loader": "andys8/purs-loader#poc/zephyr-build",
Discussion
I've still open questions. That's why this is a draft.
- The README says there is already dead code elimination. Can you provide details what is meant?
- This needs to be integrated into
bundle
. I'm not usingbundle
so far, because it will fail resolving TypeScript/Assets for me. It should be done. I can't test it. - What details are missing for documentation?
- I'm currently re-using the configured
output
directory both for the compile and zephyr step. This avoids created a temporary folder. It seems to work fine for me. Could this lead to issues?
Issues
Closes #143
I opened a PR to this branch moving package.json
's main
to "src/index.js"
. This allowed me to use this fork via git+https
, and by using this zephyr
option, it cut the size of my output by about 50%.
Usually zephyr
's output goes to dce-output
. I'm not sure if about your last comment either though.
I did run across a big issue with this recently though: you can only have one entry point. Zephyr allows you can pass in multiple files to make sure you don't dead-code-eliminate code for your other entries. Unless I missed something, this fork doesn't collect all of the imported entries and then run the DCE. I decided to drop the module all together and require()
from the appropriate /output/
or /dce-output/
folder per process.env.NODE_ENV
(similar to how many projects suggest using with Parcel).