Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/sinclairzx81/esbuild-wasm-resolve

File Resolution for Esbuild running in the Browser
https://github.com/sinclairzx81/esbuild-wasm-resolve

esbuild filesytem resolve wasm

Last synced: 3 months ago
JSON representation

File Resolution for Esbuild running in the Browser

Awesome Lists containing this project

README

        

esbuild-wasm-resolve

File Resolution for Esbuild running in the Browser


import { App } from './index.ts'

┌──────────────┐ ┌──────────────┐
│ │ ─── '/index.ts' ───> │ │
│ esbuild-wasm │ │ resolver │
│ │ <───── [code] ────── │ │
└──────────────┘ └──────────────┘




[![npm version](https://badge.fury.io/js/%40sinclair%2Fesbuild-wasm-resolve.svg)](https://badge.fury.io/js/%40sinclair%2Fesbuild-wasm-resolve)

## Overview

esbuild-wasm-resolve is a file resolver for esbuild-wasm. Due to Web Browsers not having direct access to a file system, esbuild-wasm-resolve intercepts file `read` requests made by esbuild during compilation allowing applications to resolve files externally. With this mechanism, esbuild can resolve files from IndexedDB, LocalStorage, Http or any other readable device accessible to the browser.

esbuild-wasm-resolve is primarily made with editors in mind. It is offered as is to anyone who may find it of use.

License MIT

## Install

```bash
$ npm install @sinclair/esbuild-wasm-resolve
```

## Usage

The following shows general usage.

```typescript
import { Compiler } from '@sinclair/esbuild-wasm-resolve'

const compiler = new Compiler({

resolve: path => fetch('http://localhost:5000' + path).then(res => res.text())

}, { wasmURL: 'esbuild.wasm' })

const code = await compiler.compile('/index.ts', { format: 'esm' })
//
// ^ http://localhost:5000/index.ts

console.log(code)
```

Refer to the example [here](https://github.com/sinclairzx81/esbuild-wasm-resolve/tree/main/example) for additional usage.