An open API service indexing awesome lists of open source software.

https://github.com/steelydylan/monaco-browser-bundler


https://github.com/steelydylan/monaco-browser-bundler

Last synced: about 1 year ago
JSON representation

Awesome Lists containing this project

README

          

# BrowserBundler

Bundle React and TypeScript online without Node.js

## Playground

https://mosya.dev/tools/react-ts

## Screenshots

![](./screenshot.png)

## Install

```
npm install browser-bundler
```

## Example

```js
import { browserBundle } from "browser-bundler";

const textarea = document.querySelector("#textarea") as HTMLTextAreaElement
const iframe = document.querySelector("#result") as HTMLIFrameElement

if (textarea && iframe) {
textarea.value = `import React from "react";
import ReactDOM from "react-dom";

const App = () {
return (

Hello World

}

ReactDOM.render(, document.getElementById("root"));`;

textarea.addEventListener("input", async () => {
const code = textarea.value
const { code: bundleCode } = await browserBundle(code)
iframe.srcdoc = `







${bundleCode}



`
})
textarea.dispatchEvent(new Event("input"))
```

## Relative Path

```js
import { browserBundle } from "browser-bundler";

const code = `
import React from "react";
import ReactDOM from "react-dom";
import { Hello } from "./hello.tsx";

const App = () => {
return (

)
}

ReactDOM.render(, document.getElementById("root"));
`

const result = await browserBundle(code, {
files: {
"./hello.tsx": `import React from "react";
export const Hello = () => {
return (

Hello World
)
}`,
}
})
```