Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Does this plugin also eliminate child unused modules/functions from reexports? #13

@kgrz

Description

@kgrz

I've put up a small example of this issue up at https://github.com/kgrz/webpack-side-effect-loading

In there, the polyfill.js file imports modules from files {a,b,c}.js and reexports them. The entry file entry-import-from-reexport.js imports the functions from polyfill.js, as opposed to directly from {b,c}.js, and this creates a bundle that includes React as is, compared to the entry-import-directly.js file which won't contain React.

  1. My question is, is this plugin intended to avoid such unused function bundling? This structure is quite similar to the example in your blog post, but may be I'm missing a caveat.
  2. Perhaps this is harder because React is a CJS module? We had this issue with a ES module as a second-level import (Think a React component imported in a.js which is exported as an ESM, however, one that imports React on its own)[1]. I tried reducing the problem down in this repo to demonstrate my understanding after reading the tree-shaking and module concatenation docs in webpack.
  3. Or perhaps there's a different reason due to which this is not possible?

I just wanted to see if this is not actually a bug in the plugin itself.

1: Not sure if this makes any sense with that example :|

PS: I must say, this is one of the best webpack plugins to read code, especially the choice to have two separate packages for the main logic and the plugin itself. Thank you!

PPS: I checked out the tests, and from what I gather, writing a test to simulate this multi-file import is not straight forward using the harness you have right now? Because it looks like you're parsing the code and not actually loading the imports mentioned in the test fixtures. Any other way to write a test case if this behaviour indeed is a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions