rollup-plugin-esbuild icon indicating copy to clipboard operation
rollup-plugin-esbuild copied to clipboard

add support for esbuild-wasm

Open jdalton opened this issue 3 years ago • 4 comments

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;
}

jdalton avatar Jun 22 '22 21:06 jdalton

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

curran avatar Aug 15 '23 19:08 curran

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

sxzz avatar Sep 20 '23 13:09 sxzz

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 avatar Oct 31 '23 02:10 curran

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

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

curran avatar Oct 31 '23 02:10 curran