admin管理员组

文章数量:1313077

What are the differences between

export * as bar from 'foo'

and

export { default as bar } from 'foo'

In my particular case, I've tried both of the followings, they all work, wonder the underlying differences between them.

// echarts v5.0.0
export * as ECharts from 'echarts/lib/echarts.js'
export { default as ECharts } from 'echarts/lib/echarts.js'

babel.config.js

module.exports = {
  // "@vue/cli-plugin-babel": "~4.5.0",
  presets: ['@vue/cli-plugin-babel/preset'],
}

What are the differences between

export * as bar from 'foo'

and

export { default as bar } from 'foo'

In my particular case, I've tried both of the followings, they all work, wonder the underlying differences between them.

// echarts v5.0.0
export * as ECharts from 'echarts/lib/echarts.js'
export { default as ECharts } from 'echarts/lib/echarts.js'

babel.config.js

module.exports = {
  // "@vue/cli-plugin-babel": "~4.5.0",
  presets: ['@vue/cli-plugin-babel/preset'],
}
Share Improve this question edited Jan 7, 2021 at 5:32 Wenfang Du asked Jan 5, 2021 at 1:41 Wenfang DuWenfang Du 11.5k13 gold badges76 silver badges113 bronze badges 3
  • 2 They are absolutely not the same. They might have the same result depending on what foo exports (or further, what your transpiler or module loader does with it) - please post that as well. – Bergi Commented Jan 5, 2021 at 13:22
  • Does this answer your question? Difference between import X and import * as X in node.js (ES6 / Babel)? – marzelin Commented Jan 5, 2021 at 13:45
  • @marzelin It helped, but it didn't cover the export * as syntax. – Wenfang Du Commented Jan 6, 2021 at 3:08
Add a ment  | 

1 Answer 1

Reset to default 9

This one exports all named exports and default export from foo as bar:

export * as bar from 'foo'

This one only exports default export from foo as bar:

export { default as bar } from 'foo'

本文标签: javascriptexport * as bar VS exportdefault as bar Stack Overflow