diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c9f1361..348e2d9 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,7 +7,7 @@ "type": "shell", "group": "build", // https://parceljs.org/features/cli/ - "command": "npx parcel serve src/index.html src/operator/operator.html src/presentation/presentation.html", + "command": "npx parcel serve src/index.html src/operator/operator.html src/presentation/presentation.html --no-source-maps", "presentation": { "echo": false, "reveal": "always", diff --git a/src/stateMachine/StateMachine.ts b/src/stateMachine/StateMachine.ts index 8722c84..d2011e9 100644 --- a/src/stateMachine/StateMachine.ts +++ b/src/stateMachine/StateMachine.ts @@ -9,7 +9,6 @@ import { generateDotFileForGraphviz } from "./generateDotFileForGraphviz"; import { GraphvizViewer } from "../graphvizViewer/graphvizViewer"; import Viz from "@aduh95/viz.js"; -import getWorker from "@aduh95/viz.js/worker"; interface StateMap { [stateName: string]: StateMachineState; @@ -374,8 +373,11 @@ export class StateMachine { const dotFileString = generateDotFileForGraphviz(this.allStates); - const worker = getWorker(); - const viz = new Viz({ worker }); + const viz = new Viz({ + worker: new Worker(new URL("../worker.js", import.meta.url), { + type: "module", + }), + }); viz .renderString("digraph{1 -> 2 }") diff --git a/src/worker.js b/src/worker.js new file mode 100644 index 0000000..2bdba5e --- /dev/null +++ b/src/worker.js @@ -0,0 +1,21 @@ +//import initWASM from "@aduh95/viz.js/worker"; +// If you are not using a bundler that supports package.json#exports +// use "./node_modules/@aduh95/viz.js/dist/render.browser.js" instead. +import initWASM from "../node_modules/@aduh95/viz.js/dist/render.browser.js"; + +// You need to configure your bundler to treat `.wasm` file as file to return a URL. +//import wasmURL from "@aduh95/viz.js/wasm"; +// With Rollup, use the `@rollup/plugin-url` plugin and add `**/*.wasm` to the +// `include` list in the plugin config. +// With Webpack, use the `file-loader` plugin: "file-loader!@aduh95/viz.js/wasm" + +// If you are not using a bundler that supports package.json#exports +// or doesn't have a file-loader plugin to get URL of the asset: +const wasmURL = + new URL("../node_modules/@aduh95/viz.js/dist/render.wasm", import.meta.url); + +initWASM({ + locateFile() { + return wasmURL; + }, +}); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index e3424a5..4c9bf90 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,7 +26,8 @@ // // https://parceljs.org/languages/typescript/#isolatedmodules // https://www.typescriptlang.org/tsconfig#isolatedModules - "isolatedModules": true + "isolatedModules": true, + "module": "es2022" }, "exclude": [ "node_modules"