Created
January 27, 2021 19:55
-
-
Save ryanwilsonperkin/f7ab60ecbc54c3406941325d2db9f177 to your computer and use it in GitHub Desktop.
Comparison of different import/re-export types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function a() { | |
return "a"; | |
} | |
export function b() { | |
return "b"; | |
} | |
export function c() { | |
return "c" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Comparison of different ways of importing and "re-exporting" values from example.js | |
// Import the "default" value and reuse it's intended name | |
import {default as a} from 'example'; | |
// Shortcut version of the same thing | |
import a from 'example'; | |
// Import the "default" value and give it a new name | |
import {default as a2} from 'example'; | |
// Shortcut version of the same thing | |
import a2 from 'example'; | |
// Import the named values | |
import {b, c} from 'example'; | |
// Or just one of them | |
import {b} from 'example'; | |
// Or just one of them, and rename it in the process | |
import {b as b2} from 'example'; | |
// Or all of them, stored in an object | |
import * as stuff from 'example'; // stuff === {b: b, c: c} | |
// Export the default value | |
import a from 'example'; | |
export default a; | |
// Shortcut version of the same thing | |
export {default} from 'example'; | |
// Or convert it from a default to a named export in the process | |
export {default as a2} from 'example'; | |
// Export a named value | |
import {b} from 'example'; | |
export {b}; | |
// Shortcut version of the same thing | |
export {b} from 'example'; | |
// Works with multiple values too | |
export {b,c} from 'example'; | |
// Export _all_ the named values | |
// Note: does _not_ export the default value, so "a" would not get exported | |
export * from 'example' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment