Skip to content

Allow turning off tree shaking for external modules or marking external modules as having side-effects #15486

@Lizzy-Gallagher

Description

@Lizzy-Gallagher

Feature request

What is the expected behavior?
In my application, I am seeing various external modules (specifically those with side-effect only imports, i.e. "import "myModule"") being removed by tree shaking from the bundle when in production mode.

According to the tree shaking documentation, I can mark npm packages as having side effects / not having side-effects, but that same option is not documented for external modules (even when using the function method of identifying externals).

What is motivation or use case for adding/changing the behavior?
I would like to preserve these imports since webpack can't really know if I need them or not.

My current workaround is to use "require" on only these imports (since only "import" statements are eligible for treeshaking), but that's hard to remember and I'd love to flag all externals as non-treeshakable.

How should this be implemented in your opinion?
Either

  1. Change the tree-shaking algorithm to ignore all external modules
  2. Provide a new input parameter (or options object) to the callback function for the externals function that allows specifying whether the external has side-effects or not.

Are you willing to work on this yourself?
Likely, if this isn't already secretly supported and there's buy-in on which of the two approaches to take.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Priority - Low

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions