Luca Reghellin
Luca Reghellin

Reputation: 8125

What are differences between { default as name } and { name as default } when exporting js modules?

I was taking a look to the swiper.esm.js from Swiper.js (source copied here for reference), and the first line is

export { default as Swiper, default } from './core/core.js';

while the following are of the form:

export { default as Virtual } from './modules/virtual/virtual.js';

and in MDN docs i can find that also something like

export { Something as default }

is possible. So I can currently see the following syntaxes:

export { Something as default }
export { default as Something }
export { default as Something, default }

What are the difference between the 3?

Upvotes: 0

Views: 425

Answers (1)

AKX
AKX

Reputation: 169407

// Import name `Something` from `...`, 
//   re-export as this module's default export
export { Something as default } from '...';

// Import default export from `...`, 
//   re-export as `Something` from this module
export { default as Something } from '...';

// Import default export from `...`, 
//   re-export it as `Something` from this module 
//   and this module's default export
export { default as Something, default } from '...';

Upvotes: 4

Related Questions