default
Export all as This is a Rollup plugin which will export all named exports as default
if no
default
export is specified. This makes it easy to do import pkg from 'pkg'
rather than import * as pkg from 'pkg'
, while still allowing named imports
like import { myNamedExport } from 'pkg'
.
Example
Consider the following source, which provides 3 named exports:
const namedExport1 = 42;const namedExport2 = 16180339887498948482; const inlineNamedExport = foo: 'bar' fizz: 'buzz'; ;
Build with Rollup, and you can see that in the absence of a manually specified
default
export, all named exports are provided as default
:
;; console;console;
Logs to the console:
inlineNamedExport: foo: 'bar' fizz: 'buzz' namedExport1: 42 namedExport2: 1618033988749895 inlineNamedExport: foo: 'bar' fizz: 'buzz' namedExport1: 42 namedExport2: 1618033988749895
This is done by adding an export default { ... }
statement following the
generated export { ... }
statement, i.e.:
// generated by Rollup for output.format = 'esm'; // added by this plugin: namedExport1 namedExport2 namedExport3 ;
It is effectively the same as doing:
const namedExport1 = ...;const namedExport2 = ...;const namedExport3 = ...; namedExport1 namedExport2 namedExport3;