aegir icon indicating copy to clipboard operation
aegir copied to clipboard

type: 'module' or format: 'esm' should generate esm modules

Open whizzzkid opened this issue 3 years ago • 1 comments

Right now the resulting dist/index.min.js does not provide named exports because the format is not set to esm. This happens because of padded umd banner and footer. The output should be esm which can then be imported for both the browser and node.

This can be achieved right now by setting package.json like so:

  ...
  "type": "module",
  ...
  "aegir": {
    "build": {
      "config": {
        "format": "esm",
        "banner": {
          "js": ""
        },
        "footer": {
          "js": ""
        }
      }
    }
  },
  ...

This should be selected by default if:

  1. package.json type is set to module
  2. build.config.format is esm

whizzzkid avatar Oct 20 '22 02:10 whizzzkid

Typically node modules don't import the minified files, instead the ESM source or ESM transpiled from TS in dist.

Browser modules are typically bundled too so also import the ESM source/transpiled TS.

ESM should work as a minification option though.

Would you like to submit a PR that ensures there's no UMD wrapper when build.config.format is esm?

achingbrain avatar Oct 23 '22 20:10 achingbrain