Repository navigation
Clarify Dynamic Import Limitations - #1110
Merged
Merged
Conversation
simon04
reviewed
Apr 15, 2017
simon04
left a comment
Contributor
There was a problem hiding this comment.
Thanks at lot. This makes the problem of dynamic imports much more understandable. Please address my rather minor remarks.
|
|
||
| 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. |
Contributor
There was a problem hiding this comment.
- There's one extra backtick before
import(…locale…). - "completely static" → "completely static (as
'moment'in the example above)"
| ``` | ||
| 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. |
Contributor
There was a problem hiding this comment.
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
force-pushed
the
clarify-dynamic-import-limitations
branch
from
April 15, 2017 06:45
5761eda to
e6e72ce
Compare
Contributor
Author
|
@simon04 fixed those issues, all valid points. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.