twk3 / rollup-size-compare-action

MIT License
3 stars 0 forks source link

Ignore sha's when comparing file sizes #163

Open narthur opened 2 months ago

narthur commented 2 months ago

Currently the detailed bundle breakdown looks like this when assets are built with sha's in their names.

Screenshot 2024-08-06 at 8 57 14 AM

It would be super slick if this action could account for that to make it easier to see the size differences for these files.

(p.s. thanks for the great tool!)

twk3 commented 2 months ago

I agree we need to get some option for ignoring the hash. I just haven't quite decided how do deal with the different formats to make it broadly useful. One of the complications is that rollup uses base64 hashes, where _- are valid parts of the hash. That means the hyphen you are using to separate your asset name from the hash is a bit more work to account for.

In one of the vite projects I work with the rollup config we instead switched to periods.

          chunkFileNames: 'static/js/[name].[hash].chunk.js',
          entryFileNames: 'static/js/[name].[hash].js',

Then a workaround for this limitation we strip the hash in our workflow before calling this action:

      - name: Strip content hashes from stats files
        run: |
          sed -i -E 's/index\.[0-9a-zA-Z_-]{8,}\./index./g' ./head/web-stats.json
          sed -i -E 's/\.[0-9a-zA-Z_-]{8,}\.chunk\././g' ./head/web-stats.json
          sed -i -E 's/index\.[0-9a-zA-Z_-]{8,}\./index./g' ./base/web-stats.json
          sed -i -E 's/\.[0-9a-zA-Z_-]{8,}\.chunk\././g' ./base/web-stats.json
      - uses: twk3/rollup-size-compare-action@v1.0.0
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          current-stats-json-path: ./head/web-stats.json
          base-stats-json-path: ./base/web-stats.json
          title: desktop-client

That sort of setup can be used a workaround for now, until we figure out the best way to adapt it to the happen in the action. (Do we force people to change their output to something we can detect, like with the periods, or do we let folks provide us a pattern with a fixed length hash that we find and remove.