Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

webpack.config.vendor.js and Tree-Shaking #195

Description

@avanderhoorn

As an observation, how will webpack.config.vendor.js work as Tree-Shaking becomes more common. Quickly looking at webpack.config.vendor.js it doesn't seem to have knowledge about whats being used vs not... If this is the case, maybe the prod build could work in vender dependencies there (hence webpack.config.vendor.js is only used at dev time) and webpack.config.prod.js could output the vendor as a separate file then, hence getting the best of both worlds.

Activity

  1. SteveSandersonMS commented on Jul 18, 2016

    @SteveSandersonMS
    Member

    Yep, I totally agree with your suggestion. Tree-shaking is only applicable to production builds, because with dev builds, your set of dependencies can change at any time, and you don't want to wait for re-processing all the vendor files after you make each change to your code.

    One additional thought: for production builds, I still think there's benefit in splitting the output into yourcode.js and vendor.js (where vendor.js is tree-shaken based on the usage from yourcode.js), rather than having the build just output a single merged file. This is because, for most changes to your code, you probably don't change your set of vendor dependencies, so the tree-shaken vendor.js would remain identical. Then clients don't need to re-fetch the vendor.js content if they already have it cached (they'll either get a 304 Not Changed or they won't even make a request for it, if you're referencing that file using some content-based address (like ?hash=blah) as is the default with the templates in this repo). I don't yet know whether Webpack 2's tree-shaking does that, but we can always adapt to whatever is supported.

    Closing because it doesn't seem that there's any action to take on this right now, but this is a useful discussion point for when Webpack 2 ships and we switch over to it. Thanks for raising this!

  2. avanderhoorn commented on Jul 18, 2016

    @avanderhoorn
    MemberAuthor

    No worries and agree with your comments.

  3. mcm-ham commented on Mar 31, 2017

    @mcm-ham

    @SteveSandersonMS Does it still make sense for Angular to be in vendor bundle if using AOT?

  4. SteveSandersonMS commented on Mar 31, 2017

    @SteveSandersonMS
    Member

    @mcm-ham It might not do. We'll find out when it's implemented :)

  5. JohnGalt1717 commented on Jun 9, 2017

    @JohnGalt1717

    AOT should also only be done at production and is required for Tree Shaking to fully work because the HTML has to be bundled into javascript as does the (s/l)css.

    The key is to just use vendor splitting at dev time OR use a merge tool in webpack to put them back together before doing AOT and tree shaking.

  6. ToucheSir commented on Nov 9, 2017

    @ToucheSir

    @SteveSanderson Now that tree shaking seems to be implemented (as per https://webpack.js.org/guides/tree-shaking/), is there any interest in revisiting this? Or should the discussion be moved to https://github.com/aspnet/templating since the templates are no longer in this repo?

  7. SteveSandersonMS commented on Nov 9, 2017

    @SteveSandersonMS
    Member

    @ToucheSir We're moving the templates to use whatever is the default setup for each SPA framework. For example, the Angular template will be the standard setup for an Angular CLI app, and the React template will be the standard setup for a create-react-app app. Once this is the case, the Webpack config (if any exists, usually not) will no longer be something we made any decisions about - we just use whatever the SPA framework guides people to use. As for tree shaking, I believe Angular enables that out of the box. Can't remember about React.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions