swipl-wasm 6.0.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -155,6 +155,43 @@ npm run server
|
|
|
155
155
|
Then visit <http://127.0.0.1:8080>. You should see the message "Hello world from
|
|
156
156
|
Prolog".
|
|
157
157
|
|
|
158
|
+
### Webpack Configuration for Browser Builds
|
|
159
|
+
|
|
160
|
+
When bundling `swipl-wasm` with Webpack for the browser, the underlying
|
|
161
|
+
Emscripten-generated code may import Node.js built-in modules using the `node:`
|
|
162
|
+
scheme (e.g. `node:fs`, `node:crypto`). Webpack does not handle the `node:`
|
|
163
|
+
scheme by default and will produce errors like:
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
Module build failed: UnhandledSchemeError: Reading from "node:fs" is not handled by plugins (Unhandled scheme).
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
To fix this, add the following to your `webpack.config.js`:
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
const { NormalModuleReplacementPlugin } = require('webpack');
|
|
173
|
+
|
|
174
|
+
module.exports = {
|
|
175
|
+
// ...your existing config
|
|
176
|
+
resolve: {
|
|
177
|
+
fallback: {
|
|
178
|
+
path: false,
|
|
179
|
+
fs: false,
|
|
180
|
+
crypto: false,
|
|
181
|
+
perf_hooks: false,
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
plugins: [
|
|
185
|
+
new NormalModuleReplacementPlugin(/^node:/, (resource) => {
|
|
186
|
+
resource.request = resource.request.replace(/^node:/, '');
|
|
187
|
+
}),
|
|
188
|
+
],
|
|
189
|
+
};
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
The `NormalModuleReplacementPlugin` strips the `node:` prefix so that the
|
|
193
|
+
imports are resolved by the `resolve.fallback` entries, which map them to
|
|
194
|
+
`false` (i.e. empty modules) since they are not needed in the browser.
|
|
158
195
|
|
|
159
196
|
## Browser Builds
|
|
160
197
|
|
|
@@ -211,6 +248,20 @@ The package can be built using npm. Please use npm to add new dependencies
|
|
|
211
248
|
and update the package-lock.json file. The SWI-Prolog WebAssembly version is
|
|
212
249
|
currently built inside Docker with Emscripten.
|
|
213
250
|
|
|
251
|
+
### Serving Files
|
|
252
|
+
|
|
253
|
+
When self-hosting the bundled files, ensure your server includes `charset=utf-8` in the `Content-Type` header for JavaScript files:
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
Content-Type: text/javascript; charset=utf-8
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Without the charset, WASM streaming instantiation may fail in headless browsers with errors like:
|
|
260
|
+
- Firefox: `CompileError: wasm validation error: at offset 642: byte size mismatch in type section`
|
|
261
|
+
- Chromium: `CompileError: WebAssembly.instantiate(): section was shorter than expected size`
|
|
262
|
+
|
|
263
|
+
Most static file servers (e.g., `express.static()`) set this automatically, but custom streaming handlers using `createReadStream().pipe(res)` may not.
|
|
264
|
+
|
|
214
265
|
### Development
|
|
215
266
|
|
|
216
267
|
To develop with this package, clone the repository and run:
|