Skip to content

Unexpected code after tree-shake #6264

Closed

Description

@Birowsky

Do you want to request a feature or report a bug?
Either a bug or unclear docs.

What is the current behavior?
Given entry is the entry module:
screen shot 2018-01-08 at 17 19 34

It just uses function1 from external1 module.

I expected that external1.function2 and the whole external2 module would be eliminated.

However, my output includes external2.function1. Just.. why?

Here's a repo of the whole thing.

Activity

  1. EugeneHlushko commented on Jan 14, 2018

    @EugeneHlushko
    Contributor

    While this might not be what you want, but i suggest trying webpack 4 which does not include that external2 thing.

  2. Birowsky commented on Jan 16, 2018

    @Birowsky
    Author

    @EugeneHlushko tried compiling with:

        "webpack": "4.0.0-alpha.4",
        "webpack-cli": "2.0.4"
    

    Got:

    screen shot 2018-01-16 at 10 41 43

  3. sokra commented on Jan 16, 2018

    @sokra
    Member

    This doesn't work yet. We don't do this kind of scope analysis yet, but this is prepared in some places and could be added.

  4. added this to the webpack 4.x milestone on Jan 16, 2018
  5. chengluyu commented on Mar 23, 2018

    @chengluyu

    By using ModuleConcatenationPlugin, webpack does eliminate external2 stuff correctly.

    Here's output from webpack 4 with ModuleConcatenationPlugin and UglifyJSPlugin: gist link.

  6. chengluyu commented on Mar 23, 2018

    @chengluyu

    @Birowsky You really should try out webpack 4 and ModuleConcatenationPlugin

    And don't forget to upgrade ts-loader to 4.x to avoid the error Cannot read property 'ts' of undefined.

    Or you can just try out my fork of your repo.

  7. chengluyu commented on Mar 23, 2018

    @chengluyu

    @sokra I think although there's no deep scope analysis strategy in webpack, by using ModuleConcaatenationPlugin and minifiers that supports dead code removal (e.g. UglifyJSPlugin), the same result can be achieved.

  8. Birowsky commented on Mar 24, 2018

    @Birowsky
    Author

    @chengluyu hey mate, thanx for figuring it out. However, I don't see you using the ModuleConcatenationPlugin in your fork.

  9. chengluyu commented on Mar 24, 2018

    @chengluyu

    @Birowsky I forgot to push the commit. Updated here.

  10. Birowsky commented on Apr 2, 2018

    @Birowsky
    Author

    @chengluyu finally got around to trying this. What I found was that by applying all your changes except ModuleConcatenationPlugin, things still work as I wanted them. Which is nice. But I still wonder, how exactly did you expect the ModuleConcatenationPlugin to help us with this case? I admit I don't quite understand what that plugin does, so if you can dumb it down for me, great, if not, still great :}

  11. 8 remaining items

  12. Birowsky commented on May 21, 2018

    @Birowsky
    Author

    Sorry, I won't be able to have a look into this for the next couple of weeks.

  13. dmwyatt commented on Mar 10, 2019

    @dmwyatt

    Did anything ever come of this? Any plans to integrate @vincentdchan 's work?

  14. vincentdchan commented on Mar 11, 2019

    @vincentdchan
    Contributor

    @dmwyatt Thanks for following. My plugin has been released for a while, and I rarely receive bugs report. I don't know if it's really tested by the community even though I have a lot of unit tests. Because shaking wrong modules would make production code crash. I am worried.

    @sokra Maybe I could submit a PR for integrating the plugin as an optional parameter, people can choose to use it.

  15. webpack-bot commented on Dec 3, 2019

    @webpack-bot
    Contributor

    This issue had no activity for at least three months.

    It's subject to automatic issue closing if there is no activity in the next 15 days.

  16. added
    status: stale
    on Dec 3, 2019
  17. Birowsky commented on Dec 3, 2019

    @Birowsky
    Author

    Don't you dare.

  18. removed
    status: stale
    on Dec 3, 2019
  19. jschmuecking commented on Dec 20, 2019

    @jschmuecking

    I'm not sure how relevant this is but when using your example repo the production mode achieves the elimination of external2 based on the optimizations. So for development this is reproducable with enabling the corresponding optimizations:
    optimization: { providedExports: true, usedExports: true, concatenateModules: true }
    Which actually results in the usage of beforementioned ModuleConcatenationPlugin.

    Did I misunterstand something in your requirements, @Birowsky , or does this mean the problem is fixed in webpack 4?

  20. Birowsky commented on Dec 30, 2019

    @Birowsky
    Author

    @jschmuecking, thanx for that. I can confirm that just by switching mode to 'production' in the demo repo, the unused functions are being shaken off the emitted code, and that solves my original issue.

    However, extra quality work was being done by @vincentdchan, so I'd like you to chip in.

    @tomkel, you too had some meaningful input. Please confirm that this is closable.

  21. added
    status: stale
    on Mar 30, 2020
  22. fregante commented on Apr 12, 2020

    @fregante
    Contributor

    A "Very Important" issue should not be marked "inactive."

    Bad bot!

  23. removed
    status: stale
    on Apr 12, 2020
  24. fregante commented on Apr 12, 2020

    @fregante
    Contributor

    Good boy

  25. vankop commented on Apr 12, 2020

    @vankop
    Contributor

    Work done in webpack@5. Provided example works with latest beta ([email protected]).

    I think this issue could be closed @evilebottnawi

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

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions