FredKSchott / rollup-plugin-polyfill-node

A modern Node.js polyfill for your Rollup bundle.
Other
179 stars 57 forks source link

[feat] each module as export field #63

Open loynoir opened 2 years ago

loynoir commented 2 years ago

Feat

package.json

  "exports": {
    ...
    "./node-buffer": {
      "default": {
        "import": "./node-buffer.mjs"
      }
    },
    ...
  },

So, every bundler and browser may able to use this awesome repo. 🥺🥺🥺

Thoughts

There is node:buffer pattern. So, fs/promises import id is rollup-plugin-polyfill-node/node-fs-promises

Usage: Browser

<script type="importmap">
{
  "imports": {
    "node:buffer": "https://esm.sh/rollup-plugin-polyfill-node@0.11.0/node-buffer",
  }
}
</script>

<script type="module">
import {Buffer} from "node:buffer"
console.log(Buffer)
</script>

Usage: Node

// global
console.log(Buffer)

or

import {Buffer} from "node:buffer"
console.log(Buffer)

output

import {Buffer} from "rollup-plugin-polyfill-node/node-buffer"
console.log(Buffer)