developit / developit/microbundle

Support Node conditional exports

未关闭
#594 9 条评论 0 个 reaction 已指派 1 人 已被 @developit 认领 在 GitHub 查看
enhancement :rocket: important
主要语言
JavaScript
星标
8.1k
派生
358
PR 合并指标
30 天内没有已合并 PR

描述

In node 13, there is a new option available: [`exports`](https://nodejs.org/api/esm.html#esm_conditional_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:

```jsonc
{
"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:
```jsonc
{
"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"
}
}
```

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。