lmaccherone / node-localstorage

A drop-in substitute for the browser native localStorage API that runs on node.js.
MIT License
450 stars 36 forks source link

Missing browser entry and/or sideEffects:false in package.json #89

Open andersekdahl opened 1 year ago

andersekdahl commented 1 year ago

Hi! We're using node-localstorage in Next.js apps and noticed that node-localstorage ends up in our browser bundle. We've been able to remove it by doing some webpack tomfoolery and wanted to check if this instead can be fixed in the package?

One thing is having "sideEffects": false in package.json: https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free

Another thing would be to have a browser field in package.json that points to a file that basically just does this:

module.exports = window.localStorage;

webpack and other bundlers would then prefer that file when the build target is for the browser, and you wouldn't end up with the real node-localstorage in the browser bundles.

I would have contributed with a PR but my coffeescript skills are less than ideal.