Webpack doesn’t work well with wasm modules created with Emscripten
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
- 25/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Necesita aclaración
- Estado de actividad
- Estancado
- Stack tecnológico
- javascript, wasm, webpack
- Área
- build-system, devtools
Línea de trabajo
Comienza con el proyecto de prueba mínimo enlazado y sus archivos webpack.config.js, index.js, fibonacci.js y fibonacci.wasm; ejecuta npm start para reproducir la configuración actual. Compara la configuración requerida de defaultRules, file-loader y locateFile con el manejo de wasm de Webpack. Se considera terminado cuando una salida típica de Emscripten se empaqueta automáticamente y su ruta de wasm funciona sin esta configuración personalizada.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Feature request
What is the current behavior?
The modularized JS emitted by Emscripten registers a global with a given name that loads the wasm file on invocation, initializes the wasm runtime and returns a Module.
Making it work with Webpack is quite hard as there seems to be interference with Webpack 4 defaults.
This is the webpack.config.js that I came up with:
const webpack = require("webpack");
const path = require("path");
module.exports = {
mode: "development",
entry: "./index.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle.js"
},
module: {
defaultRules: [
{
type: "javascript/auto",
resolve: {}
}
],
rules: [
{
test: /fibonacci\.js$/,
loader: "exports-loader"
},
{
test: /fibonacci\.wasm$/,
loader: "file-loader",
options: {
publicPath: "dist/"
}
}
]
},
// This is necessary due to the fact that emscripten puts both Node and
// web code into one file. The node part uses Node’s `fs` module to load
// the wasm file.
// Issue: https://github.com/kripken/emscripten/issues/6542.
plugins: [new webpack.IgnorePlugin(/(fs)/)]
};
(Here is a minimal test project in a gist that you can clone and build with npm start. Docker required!)
edit:
In the meantime, @sokra informed that that I can simplify the configuration a bit (and make it less like a sledgehammer):
module.exports = {
/* ... */
browser: {
"fs": false // ← !!
},
module: {
rules: [
/* ... */
{
test: /fibonacci\.wasm$/,
type: "javascript/auto", // ← !!
loader: "file-loader",
options: {
publicPath: "dist/"
}
}
]
},
};
Unexpected things I had to do
- I needed to overwrite
defaultRulesas otherwise some sort of default rule will run in addition to the ones I specified and making webpack error “Module parse failed: magic header not detected” (try it!) - I needed to specify
file-loaderfor the wasm file as otherwise webpack tries to resolve the names of the wasm module’s import object likeenv, which are provided by the JS file. - I needed to set a
locateFile()function as webpack changes the file (and potentially path) of the wasm file and Emscripten hardcodes that name (not visible here but in the gist)
I am not sure what the right course of action here is, but considering that most wasm projects are going to be built with Emscripten, I feel like it’s worth making it easier.
Happy to answer Qs to give y’all a clearer picture.
What is the expected behavior?
Ideally, Webpack would recognize the typical Emscripten JS files and automatically bundle the accomodating wasm module and make paths work.
Other relevant information:
webpack version: 4.8.3
Node.js version: 10
Operating System: Mac OS 10.13.4
Additional tools:
- Lenguaje dominante
- JavaScript
- Estrellas
- 66k
- Forks
- 9.7k
- Merge medio
- 8 h 12 min
- PR fusionados (30 d)
- 541
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de webpack/webpack
-
Fuzz: css syntax bug foundAbiertoarea: css
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Fuzz: html syntax bug foundAbiertoarea: html
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
CSS Modules local ident hash includes `resourceQuery` (unlike `css-loader`), causing mismatched class names for query-based imports such as `?inline`Posiblemente ocupada @alexander-akait la tomó hoy. Abiertoarea: css needs: reproduction regression
Dificultad 3/5 1-2 días Aptitud para principiantes 25/100
webpack/webpack#23696 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
`new URL('./source.js', import.meta.url)` produces a URL ending in `[object%20Module]` with a `javascript/auto` ruleQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abiertoarea: parser area: runtime
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
webpack/webpack#23271 · 8 comentarios ·
Los mantenedores suelen responder en 1 día
-
ESM output bakes hashed chunk filenames into importing modules, defeating long-term caching (no opt-out)Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertoarea: config area: runtime needs: reproduction regression
Dificultad 4/5 3-5 días Aptitud para principiantes 52/100
webpack/webpack#22056 · 6 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de webpack/webpack
Issues similares
-
Mend: dependency security vulnerability
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
ManageIQ/manageiq-ui-service#2259 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
electerious/Ackee#411 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
[bug] 提瓦特记事本原石检测框宽度较窄Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
babalae/bettergi-scripts-list#3905 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Bug] "Configure Colota" opens Colota with "Invalid configuration: No configuration data in URL"Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 87/100
dedicatedcode/reitti#1445 ·
Los mantenedores suelen responder en 1 día