stablelib
stablelib copied to clipboard
Build es, cjs and d.ts bundles
- This update allows compiling CJS, ES and D.TS bundles.
It makes possible to use modules for both types of nodejs modules - commonjs or module.
// commonjs
const base64 = require("@stablelib/base64");
// esm
import * as base64 from "@stablelib/base64";
and use modules using https://unpkg.com/ service
<script type="moduel">
import * as base64 from "https://unpkg.com/@stablelib/base64?module";
</script>
- Each module publishes only compiled files
@dchest Could you move forward this PR? I'd like to use this stablelib not on Node.js but on web browsers and Deno.
Thanks, I'm working on supporting es modules, but without rollup as it's super slow for me. Question: how would browser resolve dependencies? For example, the chacha package has these imports:
import { writeUint32LE } from "@stablelib/binary";
import { wipe } from "@stablelib/wipe";
What do you need to do to use this chacha.mjs from <script type="module">?
Also, we need to detect the system random number generator (Node or browser) at runtime, and we can't use asynchronous imports for Node's crypto in ES module.
Maybe ESBuild instead of rollup? It's hella fast compared to webpack / rollup / etc.
https://esbuild.github.io/

I haven't used SWC but it might be a good option too.
https://swc.rs/docs/benchmarks
