StableLib / stablelib

A stable library of useful TypeScript/JavaScript code
https://www.stablelib.com
Other
173 stars 35 forks source link

Build es, cjs and d.ts bundles #51

Closed microshine closed 3 months ago

microshine commented 2 years ago
  1. This update allows compiling CJS, ES and D.TS bundles.
image

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>
  1. Each module publishes only compiled files
image
dajiaji commented 2 years ago

@dchest Could you move forward this PR? I'd like to use this stablelib not on Node.js but on web browsers and Deno.

dchest commented 2 years ago

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">?

dchest commented 2 years ago

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.

joshxyzhimself commented 2 years ago

Maybe ESBuild instead of rollup? It's hella fast compared to webpack / rollup / etc.

https://esbuild.github.io/

image

I haven't used SWC but it might be a good option too.

https://swc.rs/docs/benchmarks

image