sinclairzx81 / esbuild-wasm-resolve

File Resolution for Esbuild running in the Browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

esbuild-wasm-resolve

File Resolution for Esbuild running in the Browser

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

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


npm version

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

$ npm install @sinclair/esbuild-wasm-resolve

Usage

The following shows general usage.

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 for additional usage.

About

File Resolution for Esbuild running in the Browser

License:Other


Languages

Language:TypeScript 93.9%Language:JavaScript 4.6%Language:HTML 1.3%Language:CSS 0.2%