msn0 / mdn-polyfills

MDN polyfills - from, forEach, filter, find, findIndex, assign, includes, create, entries, of, repeat, startsWith, endsWith, toggleAttribute, bind, MouseEvent, CustomEvent, padEnd, padStart
https://msn0.github.io/mdn-polyfills
175 stars 25 forks source link

Polyfills being treeshaked as deadcode #63

Open josetapadas opened 5 years ago

josetapadas commented 5 years ago

Hello,

So there is a big discussion about how self executing functions or side effects are being shaked off when, for example, you directly import one poly fill.

Imagine the following scenario:

App A includes a component from module M.

Module M imports one of your polyfills P.

When webpack compiles A, as your module has no sideEffects in package.json, it simply thinks that P is dead code.

(A nice discussion can be followed at : https://github.com/webpack/webpack/issues/6571)

What do you think of adding sideEffects to this library package.json?

Thank you!

stof commented 4 years ago

Well, the sideEffects flag allows to opt-in for side-effect-free mode (or partial side-effect-free mode when specifying some paths rather than false). If we module does not declare it, it is the same than declaring sideEffects: true. So this is already working that way.