Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 Swiperjs (source copied here for reference: https://jsfiddle.net/fw4zj8qk/), 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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

// 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 '...';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading