Skip to content

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

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    webpack-5Concerns the webpack 5 line

    Fields

    Priority

    None yet

    Start date

    None yet

    Target date

    None yet

    Effort

    None yet

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      Sponsor
      SponsoredKunjungi sekarang
      Promo