genkio/blog

ES6 module export and import, a simple example

genkio opened this issue · 0 comments

Has both export and export default in the target module.

// target module: a.js
export const a = 1
export default { b: 2, c: 3 }
// b.js
import d from './a' // d = { b: 2, c: 3}
import * as d from './a' // d = { default: { b: 2, c: 3}, a: 1 }
import defaultObject, { a } from './a' // import both default object and named property

Has only export in the target module.

// target module: a.js
export const a = 1
export const b = 2
export const c = 3
// b.js
import d from './a' // d = undefined
import { c } from './a' // c = 3
import * as d from './a' // d = { a: 1, b: 2, c: 3 }