domoritz / leaflet-locatecontrol

A leaflet control to geolocate the user.
https://domoritz.github.io/leaflet-locatecontrol/demo/
MIT License
801 stars 261 forks source link

Export dist module as default instead of src. #350

Closed RubenNL closed 5 months ago

RubenNL commented 5 months ago

This reduces the bundle size by 60%, 30.85kb to 12.37kb.

domoritz commented 5 months ago

Thanks. I did it slightly differently in 453bce6.

RubenNL commented 5 months ago

@domoritz I see you changed all of them to the dist folder, except the module one. Is this a mistake, or is there a reason for this that I can't find?

My project seems to the module export, so v0.81.0 doesn't reduce the project size for me compared to v0.79.0 :(

domoritz commented 5 months ago

The module export is for bundlers and the bundler can do its own minimization. It's standard practice I think not to use the minified version for bundlers. Are you running your own minifier?

RubenNL commented 5 months ago

I'm using vite, and I think I found the issue. My project is in the middle of a migration to ESM. It seems like "something" is parsing this library as CommonJS, but importing it as ESM. When I manually force the file to be parsed as ESM, it minifies the file correctly.

Thanks for your time, and sorry to bother you :)

EDIT: it was actually using the correct file, but the tool I used to analyze my bunde (vite-bundle-visualizer, built on rollup-bundle-visualizer), reports the size wrong.