Skip to content

Commit

Permalink
Added bundled variant of SWI build
Browse files Browse the repository at this point in the history
  • Loading branch information
rla committed Jan 28, 2023
1 parent 298ffd7 commit ea496e0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
node_modules
dist/swipl/swipl.js
dist/swipl/swipl-web.js
dist/swipl/*.js
dist/swipl/swipl-web.data
dist/swipl/swipl-web.wasm
examples/webpack/node_modules
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,34 @@ visiting <http://localhost:8080/examples/browser.html>.
In Nodejs:

```js
const SWIPL = require("swipl-wasm/dist/swipl");

const swipl = await SWIPL({ arguments: ["-q"] });
console.log(swipl.prolog.query("member(X, [a, b, c]).").once().X);
```

You can run this example with `node examples/run-on-node.js`.

## Using single-file bundle

The `swipl-wasm` package comes also with the single-file bundle. This does not
require distributing the `.data` and `.wasm` files which are now embedded into
the `.js` file instead.

```html
<div id="solution"></div>
<script src="/dist/swipl/swipl-bundle.js"></script>
<script>
(async () => {
const swipl = await SWIPL({ arguments: ["-q"] });
const query = "member(X, [a, b, c]).";
const solutionElement = document.getElementById("solution");
const firstSolution = swipl.prolog.query(query).once().X;
solutionElement.textContent = firstSolution;
})();
</script>
```

## Running JavaScript from Prolog

This uses `eval`:
Expand Down
2 changes: 2 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import SWIPL = require("./common");
export = SWIPL;
1 change: 1 addition & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("./swipl/swipl-bundle");
2 changes: 2 additions & 0 deletions dist/swipl/swipl-bundle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import SWIPL = require("../common");
export = SWIPL;
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
],
"license": "BSD-2-Clause",
"type": "commonjs",
"main": "dist/index.js",
"types": "dist/index.d.js",
"devDependencies": {
"@types/node": "^18.7.14",
"@typescript-eslint/eslint-plugin": "^5.39.0",
Expand All @@ -30,6 +32,7 @@
"build:wasm-docker:extract:data": "docker cp swipl-wasm:/swipl-devel/build.wasm/src/swipl-web.data dist/swipl/swipl-web.data",
"build:wasm-docker:extract:wasm": "docker cp swipl-wasm:/swipl-devel/build.wasm/src/swipl-web.wasm dist/swipl/swipl-web.wasm",
"build:wasm-docker:extract:web": "docker cp swipl-wasm:/swipl-devel/build.wasm/src/swipl-web.js dist/swipl/swipl-web.js",
"build:wasm-docker:extract:bundle": "docker cp swipl-wasm:/swipl-devel/build.wasm/src/swipl-bundle.js dist/swipl/swipl-bundle.js",
"build:wasm-docker:extract:node": "docker cp swipl-wasm:/swipl-devel/build.wasm/src/swipl-web.js dist/swipl/swipl.js",
"build:wasm-docker:extract": "run-s build:wasm-docker:extract:*",
"build:wasm-docker": "run-s build:wasm-docker:build build:wasm-docker:create build:wasm-docker:extract build:wasm-docker:remove",
Expand Down

0 comments on commit ea496e0

Please sign in to comment.