stealjs / steal-tools

Build easy. Load fast.

Home Page:https://stealjs.com/docs/steal-tools.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support sideEffects configuration for tree-shaking

matthewp opened this issue · comments

WebPack has a sideEffects configuration that is used to control what modules can be tree-shaken.

In steal-tools@pre we don't use this. In WebPack, iirc, it will only tree shaken modules explicitly marked as sideEffects: false. We don't want to support that part, but we do want to support this form:

{
  "sideEffects": ["some-module"]
}

Which will prevent some-module from being tree-shaken.

I can't remember why we need this... I think maybe we don't. Going to remove this from the 2.0 epic, can add later in a minor release if there becomes a need.

For something like can-stache-bindings?

It depends on how you import it. If you do:

import "can-stache-bindings";

It will be included in the build. However if you do:

import stacheBindings from "can-stache-bindings";
// stacheBindings is never used

Then it would be tree-shaken currently. This configuration would prevent that.

What about

import {stacheBindings} from “can”

But stacheBindings isn’t used in the file.

Would be tree shaken. However, if you're using Component as well then it will be included since that depends on it.

So with this configuration a user could do:

{
  "sideEffects": ["can-stache-bindings"]
}

And then it would be included. Unfortunately canjs couldn't add this config, otherwise it would be included in the bundle whether someone used it or not.