5

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'],
}
Wenfang Du
  • 8,804
  • 9
  • 59
  • 90
  • 2
    They are [absolutely not the same](https://stackoverflow.com/q/32236163/1048572). 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 Jan 05 '21 at 13:22
  • Does this answer your question? [Difference between import X and import \* as X in node.js (ES6 / Babel)?](https://stackoverflow.com/questions/31386631/difference-between-import-x-and-import-as-x-in-node-js-es6-babel) – marzelin Jan 05 '21 at 13:45
  • @marzelin It helped, but it didn't cover the `export * as` syntax. – Wenfang Du Jan 06 '21 at 03:08

1 Answers1

6

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'
Wenfang Du
  • 8,804
  • 9
  • 59
  • 90