What are the different ways to export and re-export things from a module?
There are three ways to export things and four ways to import them, and knowing all of them is what lets you read any module file quickly.
On the export side, there are three forms. You can put export in front of a declaration, so that the declaration and the export happen together. You can export a list of names that already exist at the bottom of the file with a single export statement. And you can mark one name as the default export, which is the main export of the module and the only default that a file may have.
On the import side, there are four forms. A named import uses braces and pulls one or more specific exports. A default import has no braces and gives you the default export under a name that you choose. A namespace import uses the star syntax and gives you an object that holds every export. And you can combine a default import with named imports in one statement by putting the default name first and the named ones in braces after it.
Re-exports let a module forward what another module exports. The export from form forwards specific names, the star form forwards everything except the default, and you can also re-export a default under a new name. A module that gathers exports from several files and publishes them as one is called a barrel file, and it is a common way to give a package a single entry point.
There is one warning about barrels. Every file in the barrel is loaded when anything in the barrel is imported, so a barrel that re-exports large modules can slow down your start-up time and make your bundle bigger. Many teams keep one barrel for the public API and use direct imports inside the package.