egoist / rollup-plugin-esbuild

Use ESBuild with Rollup to transform ESNext and TypeScript code.
MIT License
630 stars 41 forks source link

add support for esbuild-wasm #342

Open jdalton opened 2 years ago

jdalton commented 2 years ago

Would adding esbuild-wasm as a peer-dependency and loading esbuild as:

function requireEsbuild() {
  let error;
  try {
    return require('esbuild');
  } catch (e) {
    error = e;
  }
  try {
    return require('esbuild-wasm');
  } catch {}
  throw error;
}
curran commented 1 year ago

I'm also interested in making rollup-plugin-esbuild work in the browser using esbuild-wasm.

sxzz commented 1 year ago

We'd like to accept this feature if anyone can make a PR for it.

curran commented 1 year ago

Wouldn't it be more like this?

async function requireEsbuild() {
  try {
    return await import('esbuild');
  } catch (error) {
    try {
      return await import('esbuild-wasm');
    } catch {
      throw error;
    }
  }
}

Alternatively, what if we allowed consumers to provide their own instance of ESBuild in the plugin constructor? That would allow consumers of the plugin to import ESBuild-WASM however they like.

curran commented 1 year ago

For a browser build we'd also need to remove these dependencies:

import { existsSync, statSync } from 'fs'
import { extname, resolve, dirname, join } from 'path'