Microbundle: Support Node conditional exports

Created on 23 Apr 2020  路  1Comment  路  Source: developit/microbundle

In node 13, there is a new option available: exports.

As this will be the new standard for defining packages available for node/browsers/etc, it could be nice to use it instead/addition of the module, unpkg etc. fields in the current package.json. Webpack also plans to support it in the v5: https://github.com/webpack/webpack/issues/9509

Current API:

{
  "source": "src/foo.js",           // Your source file (same as 1st arg to microbundle)
  "main": "dist/foo.js",            // output path for CommonJS/Node
  "module": "dist/foo.module.js",   // output path for JS Modules
  "unpkg": "dist/foo.umd.js",       // optional, for unpkg.com
  "scripts": {
    "build": "microbundle",         // uses "source" and "main" as input and output paths by default
    "dev": "microbundle watch"
  }
}

New API:

{
  "source": "src/foo.js",           // Your source file (same as 1st arg to microbundle)
  "main": "dist/foo.js",            // output path for CommonJS/Node
  "exports": { 
    "import": "dist/foo.module.js", // output path for JS Modules
    "browser": "dist/foo.umd.js",   // optional, for unpkg.com
  },
  "scripts": {
    "build": "microbundle",         // uses "source" and "main" as input and output paths by default
    "dev": "microbundle watch"
  }
}
enhancement important

Most helpful comment

Hiya @Ayc0 - thanks for opening an issue for this, it's been on my mind a lot. I have an implementation that should be able to be airlifted into Microbundle, hopefully I'll get some time this week or next.

>All comments

Hiya @Ayc0 - thanks for opening an issue for this, it's been on my mind a lot. I have an implementation that should be able to be airlifted into Microbundle, hopefully I'll get some time this week or next.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pascalduez picture pascalduez  路  12Comments

zzswang picture zzswang  路  14Comments

smithki picture smithki  路  19Comments

Conaclos picture Conaclos  路  11Comments

gamtiq picture gamtiq  路  28Comments