evanw/esbuild

Library exports

Opened this issue · 2 comments

In Webpack, it's possible to use output.library.export to choose the export of the namespace object that will be exposed as a library. For example, if my file is

export function namedExport(): string {
    return "namedExport";
}

export default function defaultExport(): string {
    return "defaultExport";
}

I can add

library: {
    name: 'MyLibrary',
    type: 'var',
    export: 'default',
},

and my bundle will not include the named export. Is there something similar that can be done in esbuild with the iife format?

You can use the banner and footer options to wrap the final iife bundle. For example: (try)

globalName: '_mod',
footer: 'var MyLibrary = _mod.default; _mod = void 0;'

Thanks for the nice example. This is almost what I need -- my main issue is that the bundle would still contain the named exports.