Skip to content

Treat dynamic imports as chunks, not entry points #2407

Closed

Description

@guybedford

Feature Use Case

As mentioned in #2406 (comment), dynamic imports aren't necessarily entry points from a user perspective.

There are significant code splitting optimizations to be found in removing the facade and chunking constraints of treating dynamic imports as entry points as well.

Feature Proposal

We treat dynamic imports as entry points because that was the easiest way to add them to the chunking colouring algorithm, but it would actually be an improvement to the chunking algorithm if we could work out the common base dependencies of a given dynamic import (the intersection of the static dependency graph of all modules that use this dynamic import) as that would result in fewer chunks and a significant optimization to the algorithm overall.

The other side of this is that dynamic imports also shouldn't need to maintain their facades. We could do this the same way we handle namespaces for other modules, creating the namespace internally as a JS object in the chunk and then exporting that. So this would effectively do (import('x').then(x => ...) -> import('chunk-x').then(x => x.dynamicX).then(x => ...) sort of thing. This would be important to allow chunk grouping with dynamic module chunks, which was one of the reasons we treat them as entry points as well to maintain their facades.

Will see if I can get a PR up along these directions in the next couple of weeks.

Update

Some of this has been implemented via #2575. Nevertheless, two major open points remain:

  • The colouring algorithm for dynamic imports should skip modules that are already in the same graphs as all importing files. See Refactor chunking algorithm #2575 (comment) for a nice detailed example of what this is about.
  • Dynamic imports could be handled via either inlining the facade or having an additional namespace on the import that is extracted.

Activity

  1. lukastaegert commented on Aug 20, 2018

    @lukastaegert
    Member

    Sounds awesome, this is something I keep stumbling about as well.

  2. manucorporat commented on Aug 25, 2018

    @manucorporat
    Contributor

    @lukastaegert @guybedford will this finally rename dynamic import paths so the filename includes the hash?

  3. shellscape commented on Aug 10, 2019

    @shellscape
    Contributor

    Hey folks. This is a saved-form message, but rest assured we mean every word. The Rollup team is attempting to clean up the Issues backlog in the hopes that the active and still-needed, still-relevant issues bubble up to the surface. With that, we're closing issues that have been open for an eon or two, and have gone stale like pirate hard-tack without activity.

    We really appreciate the folks have taken the time to open and comment on this issue. Please don't confuse this closure with us not caring or dismissing your issue, feature request, discussion, or report. The issue will still be here, just in a closed state. If the issue pertains to a bug, please re-test for the bug on the latest version of Rollup and if present, please tag @shellscape and request a re-open, and we'll be happy to oblige.

  4. lukastaegert commented on Aug 10, 2019

    @lukastaegert
    Member

    I think the two open points are still important to be resolved and are referenced quite often.

  5. lukastaegert commented on Sep 22, 2019

    @lukastaegert
    Member

    Closed in favour of #3124 and #3125

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions