egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
9.01k stars 217 forks source link

Esbuild wasm plugin not working. #981

Open nohaapav opened 1 year ago

nohaapav commented 1 year ago
import { defineConfig } from 'tsup';
import { wasmLoader } from 'esbuild-plugin-wasm';

const wasmPlugin = wasmLoader({ mode: 'embedded' });

export default defineConfig(({ watch }) => ({
  entry: ['src/index.ts'],
  format: 'esm',
  outDir: 'build',
  target: 'esnext',
  minify: true,
  clean: true,
  esbuildPlugins: [wasmPlugin],
  esbuildOptions(options, context) {
    context.format = 'esm';
  },
  outExtension({ format }) {
    console.log(format);
    const ext = format === 'esm' ? 'mjs' : 'cjs';

    return {
      js: `.${ext}`,
    };
  },
}));

If i use plugin directly in esbuild wasms are loaded see:

// ESM bundle
esbuild
  .build({
    entryPoints: ['src/index.ts'],
    outfile: 'build/index.mjs',
    bundle: true,
    minify: true,
    plugins: [wasmPlugin],
    format: 'esm',
    platform: 'browser',
    target: ['esnext'],
  })
  .catch(() => process.exit(1));

Upvote & Fund

Fund with Polar

nohaapav commented 1 year ago

Seems like some issue with filter, see not picking up: /\.(?:wasm)$/