Skip to content

Clarify Dynamic Import Limitations - #1110

Merged
simon04 merged 1 commit into
masterfrom
clarify-dynamic-import-limitations
Apr 15, 2017
Merged

simon04 merged 1 commit into
masterfrom
clarify-dynamic-import-limitations

Conversation

@skipjack

Copy link
Copy Markdown
Contributor

This is an attempt to resolve #1083 and could also potentially address #1099, however #1099 is in relation to require.resolve. Maybe this can be tweaked somehow to accommodate both cases.

This will conflict with some other PRs that are currently open but I'd be happy to rebase once those are merged. In the meantime, hoping someone can give this a quick review to make sure I have everything right.

@skipjack
skipjack requested review from bebraw and simon04 April 15, 2017 04:12

@simon04 simon04 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks at lot. This makes the problem of dynamic imports much more understandable. Please address my rather minor remarks.

Comment thread content/guides/code-splitting-import.md Outdated

Note that fully dynamic statements, such as `import(foo)`, __will fail__ because webpack requires at least some file location information. This is because `foo` could potentially be any path to any file in your system or project. The `import(...)` must contain at least some information about where the module is located, so bundling can be limited to a specific directory or set of files.

For example, `` `import(`./locale/${language}.json`)`` will cause every `.json` file in the `./locale` directory to be bundled into the split point. At run time, when the variable `language` has been computed, any file like `english.json` or `german.json` will be available for consumption. So keep in mind that when using `import()`, the path must contain some path information or be completely static.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • There's one extra backtick before import(…locale…).
  • "completely static" → "completely static (as 'moment' in the example above)"

Comment thread content/guides/code-splitting-import.md Outdated
```
T> 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')`).

Note that fully dynamic statements, such as `import(foo)`, __will fail__ because webpack requires at least some file location information. This is because `foo` could potentially be any path to any file in your system or project. The `import(...)` must contain at least some information about where the module is located, so bundling can be limited to a specific directory or set of files.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two minor remarks right at the beginning:

  • "split point" → "split-point" (same typesetting as in the intro above the example)
  • import(...) → import()? (We've been referring to this always without arguments. But I see that here you want to stress the argument. Decide yourself. 😄)

@skipjack
skipjack force-pushed the clarify-dynamic-import-limitations branch from 5761eda to e6e72ce Compare April 15, 2017 06:45
@skipjack

Copy link
Copy Markdown
Contributor Author

@simon04 fixed those issues, all valid points.

@simon04 simon04 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you!

@simon04
simon04 merged commit 53f8b85 into master Apr 15, 2017
@skipjack
skipjack deleted the clarify-dynamic-import-limitations branch April 17, 2017 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants