mediamonks / isntnt

A collection of composable JavaScript runtime type predicates with TypeScript type guard declarations
Other
6 stars 2 forks source link

Tree shaking isn't working correctly #5

Closed hjeti closed 3 years ago

hjeti commented 3 years ago

The package now supports esm but tree shaking doesn't work yet when used in webpack. A single import of a predicate will import everything from the package.

I didn't understand why so I started searching and found this: https://webpack.js.org/guides/tree-shaking/ I also looked at a package like lodash-es and found that they have sideEffects: false in their package.json as stated in the guide. The lodash package does proper treeshaking as far as I could see because of that sideEffects property. As a test I added the property to this package as well and it seemed to work the included size went from 13kb to 1kb in my case. I don't know the complete package to know if there are actual side effects. If not then it's just a case of adding that property to the package.json.

ThaNarie commented 3 years ago

Afaik all functions are pure, so I think it's indeed safe to set this sideEffects: false.

I'll get this in and publish a new version.

ThaNarie commented 3 years ago

Published as 1.4.5