Feature request: support package.json conditional exports

Abierto
#27,904 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
cpp, javascript, wasm
Área
build-system

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
C++
Estrellas
27.8k
Forks
3.6k
Merge medio
1 d 6 h
PR fusionados (30 d)
181

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de emscripten-core/emscripten

Todos los issues de emscripten-core/emscripten

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.