import es6 code example
Example 1: alias import javascript
import {default as alias} from 'my-module';
Example 2: 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 3: javascript import
import { module } from "./path";
import Module from "./path";
import Module, { module } from "./path";
Example 4: import all from javascript
import * as module from "./module.js";
Example 5: import javascript
import { add } from './math_functions.js';
import { add, someothervariable } from './math_functions.js';
Example 6: different types ways of export and import in javascript
import 'example';
import exampleDefaultExport from 'example';
import { property } from 'example';
import { property as exampleProperty } from 'example';
import * as example from 'example';
export var property = 'example property';
export function property() {};
export default 'example default';
var property = 'example property';
export { property };
export { property as exampleProperty };
export { property as exampleProperty } from 'example';
export * from 'example';