Packages in browser

I have a body of Prolog code that I wish to run in a web browser. (That is, client-side, not server-side.) I’ve obtained the WASM build from the npm package swpl-wasm 3.4.3, and copied the necessary files to a web server, and it almost works. The one problem is that several of my source files contain the line:

:- use_module(library(function_expansion)).

This provokes the error:

ERROR:    source_sink `library(function_expansion)' does not exist

Presumably this is because the function_expansion package is not part of the core libraries included in swipl-web.data.

Now, I can get rid of the error by loading function_expansion from a URL instead, like:

:- use_module("../library/function_expansion").

And if I do this in every prolog file where it occurs, the code runs without problems.
But I’m reluctant to do that, because this code is also used in other contexts, and it would be inconvenient to fork it into browser and non-browser versions.

What is the preferred approach to loading packages that aren’t included in swipl-web.data? Will I have to build a custom version that includes function_expansion, or is there a simpler way?

One way is possibly to use qcompile/2 as described in SWI-Prolog -- Manual to create a single file. If that works it probably also loads a lot faster.

If that doesn’t work, there are surely other routes, so just asks again :slight_smile: