Allow app authors to force libraries into sideEffects: false`

Do you want to request a feature or report a bug?

Feature Request

What is the current behavior?

sideEffects: false is (or will be, in webpack 4) a library-level setting.

If the current behavior is a bug, please provide the steps to reproduce.

N/A

What is the expected behavior?

N/A

If this is a feature request, what is motivation or use case for changing the behavior?

It would be incredibly useful to have a way for app authors to opt libraries into this behavior, possibly for cases where library authors never added this setting themselves, for whatever reason.

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

N/A

Author: Fantashit

5 thoughts on “Allow app authors to force libraries into sideEffects: false`

  1. I suspect that in many cases instead of selectively opting certain libraries in as side effect-free, the builder of an app will want to blanket declare all packages they use to be free of side effects unless explicitly stated otherwise. Innocent until proven guilty offers the least hassle for achieving maximal tree shaking potential as new dependencies are added over time. Perhaps an "include"/"exclude"-style pattern would be ideal to allow for a combination of whitelisting and blacklisting.

  2. Of course! The purpose of a blacklist wouldn’t be to override library authors who declared "sideEffects": false, although it could be used for that if it turned out they were mistaken. The main use case is so that, assuming many packages don’t specify the flag one way or the other, you can by default assume all packages to be side effect-free, then pick out the ones which turn out to have side effects.

  3. We’ll add sideEffects: false to the rules:

    module.rules: [
      {
        include: path.resolve("node_modules", "lodash"),
        sideEffects: false
      }
    ]
  4. @sokra Adding it to rules only would give this configuration power and responsibility only to application developers (usually for libraries webpack is used only to generate UMD bundle ready for a browser and bundling is left for app devs), however it would be nice to give it also for libraries authors, as they are the ones who know the best which module causes side effects, and which doesn’t.

    For example, lets say I am creator or a library with this index.js:

    export { x } from './x';
    export { y } from './y'; // causes a side effect

    A library consumer shouldn’t be forced to dig into source code to search for side effects. And, because module ./y causes a side effect, me, the library author, cannot set sideEffects: false in the library’s package.json. So, would you consider allowing sideEffects as object in package.json, like:

    {
      "sideEffects": {
        "./x": false,
        "./y": true
      }
    }

Comments are closed.