Compile esm.sh to a local CLI that builds esm on your computer
This is useful for people don't like loading JS files from a CDN, but want the esm version of a CJS module on NPM. The idea has been discussed on bsky:
Usage:
esm.sh add --local react react/ react-dom react-dom/
vendor/
├── react.mjs (react@18.3.1, 9.41KB)
├── react/jsx-runtime.mjs (react@18.3.1, 2.39KB)
├── react/jsx-dev-runtime.mjs (react@18.3.1, 38.96KB)
├── react-dom.mjs (react-dom@18.3.1, 129.19KB)
├── react-dom/client.mjs (react-dom@18.3.1, 1.54KB)
└── react-dom/server.mjs (react-dom@18.3.1, 70.67KB)
Updating importmap...
✅ index.html
✅ blog/how-to-import-a-javascript-library.html
then you can import modules like:
<script type="module">
import { useState } from "./vendor/react.mjs"
import { createRoot } from "./vendor/react-dom/client.mjs"
</script>
with import map:
<script type="importmap">
{
"imports": {
"react": "./vendor/react.mjs",
"react-dom/client": "./vendor/react-dom/client.mjs"
}
}
</script>
<script type="module">
import { useState } from "react" // "./vendor/react.mjs"
import { createRoot } from "react-dom/client" // "./vendor/react-dom/client.mjs"
</script>
Progress:
Compile esm.sh to a local CLI that builds esm on your computer
This is useful for people don't like loading JS files from a CDN, but want the esm version of a CJS module on NPM. The idea has been discussed on bsky:
Usage:
then you can import modules like:
with import map:
Progress: