Skip to content

More Clarity In Docs Needed on Limitations of Dynamic Imports in Webpack 2 #1083

Closed

Description

@bdwain

This page in the docs only has a quick sentence about how import statements cannot be "fully" dynamic, but can be partly.

Keep in mind that import() path cannot be fully dynamic (e.g., import(Math.random())). Rather either completely static (e.g., import('./locale/de.json')) or partially static (e.g., import('./locale/' + language + '.json')).

Ideally the docs would provide details on when and how variable names can be used in import statements. For example, something like this doesn't work.

export function foo(deps){
  deps.forEach(dep => import(dep).then(doSomething))
}
//usage:
foo(['bar', 'baz']);

but this does (according to the docs at least)

import('./locale/' + language + '.json')).

it would be helpful if there was more detail about when dynamic import paths are allowed and what parts of them can be dynamic (it seems like the beginning needs to be static?).

Thanks for the help! I appreciate all of the work you all do on this.

Activity

  1. bdwain commented on Apr 6, 2017

    @bdwain
    ContributorAuthor

    Also I'm happy to make the pr to the docs. I just need the questions answered before I can do it. Thanks!

  2. simon04 commented on Apr 6, 2017

    @simon04
    Contributor
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

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions