Skip to content

ProvidePlugin can't tree shaking like the doc said #4008

@Chen-jj

Description

@Chen-jj

Bug report

What is the current behavior?

When using ProvidePlugin to provide join of lodash or lodash-es, the output bundle can't drop the rest of lodash as docs said: https://v4.webpack.js.org/guides/shimming/#shimming-globals

image

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

Follow the Getting Started & Shimming steps from docs.

  1. git clone git@github.com:Chen-jj/webpack-demo.git
  2. yarn && npm run build
  3. When using ProvidePlugin, the bundle size is about 99.4k.
    While using import { join } from 'lodash-es' instead the size is about 1.13k.

What is the expected behavior?

The output bundles contain lodash.join.

Other relevant information:
webpack version: 4.44.2
Node.js version: 12.14
Operating System: MacOS
Additional tools:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions