1// something.js
2
3export const hi = (name) => console.log(`Hi, ${name}!`)
4export const bye = (name) => console.log(`Bye, ${name}!`)
5export default () => console.log('Hello World!')
6
7We can use import() syntax to easily and cleanly load it conditionally:
8// other-file.js
9
10if (somethingIsTrue) {
11 import('./something.js').then((module) => {
12 // Use the module the way you want, as:
13 module.hi('Erick') // Named export
14 module.bye('Erick') // Named export
15 module.default() // Default export
16 })
17}
1import defaultExport from "module-name";
2import * as name from "module-name";
3import { export1 } from "module-name";
4import { export1 as alias1 } from "module-name";
5import { export1 , export2 } from "module-name";
6import { foo , bar } from "module-name/path/to/specific/un-exported/file";
7import { export1 , export2 as alias2 , [...] } from "module-name";
8import defaultExport, { export1 [ , [...] ] } from "module-name";
9import defaultExport, * as name from "module-name";
10import "module-name";
11var promise = import("module-name");
12
1/*Imagine a file called math_functions.js that contains several functions
2related to mathematical operations. One of them is stored in a variable called
3add.*/
4
5//If you want to import one item:
6import { add } from './math_functions.js';
7
8//If you want to import multiple items:
9import { add, someothervariable } from './math_functions.js';