Feature request: support package.json conditional exports

Aperta
#27,904 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
cpp, javascript, wasm
Ambito
build-system

Direzione di ricerca

Start by reading how emcc handles multiple target environments and generates JavaScript glue, then review the related issue #21899 and the conditional exports approach described here. The issue does not name specific source files or tests; first determine how variants could share one WebAssembly binary without rebuilding it for each environment. Done means emcc can produce environment-specific glue with conditional exports while sharing the binary.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Currently, when multiple environments are provided to emcc, it generates a JavaScript file similar to this:

async function MyModule(moduleArg = {}) {
  var Module = moduleArg;
  var ENVIRONMENT_IS_WEB = !!globalThis.window;
  var ENVIRONMENT_IS_WORKER = !!globalThis.WorkerGlobalScope;
  var ENVIRONMENT_IS_NODE =
    globalThis.process?.versions?.node &&
    globalThis.process?.type != "renderer";
  // ...
}

The thing is, since this output relies on checking globalThis, it is difficult to treeshake in bundlers. It also ships a little bit of unnecessary code for users.

A solution could be to use package.json conditional exports.

The problem is there seems to be no easy to way to output multiple variants of JS glue code, but only one WebAssembly binary. For example, the wasm-vips library handles this through a custom build script that builds it for both Node and the browser before collapsing the WebAssembly binary into one file. This can be very time consuming, especially if LTO is enabled.

Related: #21899

Lingua principale
C++
Stelle
27.8k
Fork
3.6k
Merge medio
1g 6h
PR unite (30g)
181

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di emscripten-core/emscripten

Tutte le issue di emscripten-core/emscripten

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.