dynamically import named import code example
Example 1: js es6 dynamic import default
export const hi = (name) => console.log(`Hi, ${name}!`)
export const bye = (name) => console.log(`Bye, ${name}!`)
export default () => console.log('Hello World!')
We can use import() syntax to easily and cleanly load it conditionally:
if (somethingIsTrue) {
import('./something.js').then((module) => {
module.hi('Erick')
module.bye('Erick')
module.default()
})
}
Example 2: import javascript
import { add } from './math_functions.js';
import { add, someothervariable } from './math_functions.js';