May 2018
Intermediate to advanced
470 pages
13h 54m
English
Dynamic import() is a new function-like version of the regular import and it enables the dynamic loading of JS modules. Using import(moduleSpecifier) will return a promise for the module namespace object of the requested module. When using regular static imports, we import a module at the top of the code and then use it in the code:
import { convert } from './metric'...console.log(convert('km', 'miles', 202))
If we were to use dynamic import() instead of adding the static import at the beginning, the code would look like this:
import('./metric').then({ convert } => { console.log( convert('km', 'miles', 202) ) })
This allows importing and loading the module when the code requires it. While bundling the application code, Webpack ...
Read now
Unlock full access