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.

    For the options you used, --format=iife is the default. When each format is chosen as the default can be seen in the --format documentation.