npm.io
0.9.2 • Published 1 year ago

esm-compiler

Licence
MIT
Version
0.9.2
Deps
0
Size
6.4 MB
Vulns
0
Weekly
0
Stars
33

ESM Compiler

The compiler for esm.sh playground written in Rust, powered by swc and lightningcss.

Usage

import init, { transform } from "https://esm.sh/esm-compiler";
await init();

const appTsx = `
import { useState } from "react"

export default App() {
  const [msg] = useState<string>("world")
  return <h1>Hello {msg}!</h1>
}
`
const importMap = {
  imports: {
    "@jsxImportSource": "https://esm.sh/react@18"
    "react": "https://esm.sh/react@18",
  }
}
const ret = transform("./App.tsx", appTsx, { importMap })
console.log(ret.code)

Development Setup

You will need rust 1.60+ and wasm-pack.

Build

wasm-pack build --target web

Run tests

cargo test --all