Search code examples
javascripttypescriptesbuild

How to get esbuild to export a default module vs IIFE's


I want it to export this ts entry

with a export default (so I can dynamically import it in browser) not as shown below:

enter image description here

I ran esbuild like so:

"esbuild": "esbuild src/i18n/en.ts --bundle --outfile=dist/i18n/en.js",


Solution

  • To specify the format of the output, esbuild has the flag --format.

    To emit esm you can use --format=esm.

    The default for --format depends on what other options you have passed. You can see when which --format is chosen in the documentation.

    The iife format will automatically be enabled when no output format is specified, bundling is enabled, and platform is set to browser (which it is by default)