From ae5940718ec0bc9749dc296f5dc75de133f5cd77 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Fri, 4 Jul 2025 03:09:11 +0100 Subject: [PATCH] Use wrapper in example --- .vscode/settings.json | 1 + examples/website/.gitignore | 3 -- examples/website/script.js | 11 ++++--- reconcile-js/tsconfig.json | 7 ++++- reconcile-js/webpack.config.js | 52 ++++++++++++++++++---------------- scripts/dev-website.sh | 10 +++---- 6 files changed, 44 insertions(+), 40 deletions(-) delete mode 100644 examples/website/.gitignore diff --git a/.vscode/settings.json b/.vscode/settings.json index c8ff44a..0639673 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,6 @@ "**/snapshots": true, // cargo-insta outputs "pkg": true, // wasm-pack build directory "target": true, // rust build directory + "**/node_modules": true, // node.js dependencies } } \ No newline at end of file diff --git a/examples/website/.gitignore b/examples/website/.gitignore deleted file mode 100644 index 8c5f1db..0000000 --- a/examples/website/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -reconcile.js -reconcile_bg.wasm - diff --git a/examples/website/script.js b/examples/website/script.js index b81cf29..1f5fafe 100644 --- a/examples/website/script.js +++ b/examples/website/script.js @@ -1,4 +1,4 @@ -import init, { mergeTextWithHistory } from "./reconcile.js"; +import { init, reconcileWithHistory } from "./dist/index.js"; const originalTextArea = document.getElementById("original"); const leftTextArea = document.getElementById("left"); @@ -37,16 +37,15 @@ function updateMergedText() { const left = leftTextArea.value; const right = rightTextArea.value; - const results = mergeTextWithHistory(original, left, right); + const results = reconcileWithHistory(original, left, right); mergedTextArea.innerHTML = ""; - for (const result of results) { + for (const {text, history} of results.history) { const span = document.createElement("span"); - span.className = result.history(); - span.textContent = result.text(); + span.className = history; + span.textContent = text; mergedTextArea.appendChild(span); - result.free(); } } diff --git a/reconcile-js/tsconfig.json b/reconcile-js/tsconfig.json index c307f61..238bbbb 100644 --- a/reconcile-js/tsconfig.json +++ b/reconcile-js/tsconfig.json @@ -4,9 +4,14 @@ "target": "ESNext", "strict": true, "allowSyntheticDefaultImports": true, + "esModuleInterop": true, "moduleResolution": "bundler", "declaration": true, - "declarationDir": "./dist/types" + "declarationDir": "./dist/types", + "outDir": "./dist", + "rootDir": "./src", + "skipLibCheck": true, + "inlineSourceMap": true }, "exclude": [ "./dist" diff --git a/reconcile-js/webpack.config.js b/reconcile-js/webpack.config.js index 9d54c6b..64f1ee5 100644 --- a/reconcile-js/webpack.config.js +++ b/reconcile-js/webpack.config.js @@ -1,33 +1,37 @@ const path = require("path"); -const webpack = require("webpack"); -const packageJson = require("./package.json"); module.exports = { - entry: "./src/index.ts", - module: { - rules: [ - { - test: /\.ts$/, - use: ["ts-loader"] - }, - { - test: /\.wasm$/, - type: "asset/inline" - } - ] - }, - resolve: { - extensions: [".ts"], - alias: { - root: __dirname, - src: path.resolve(__dirname, "src") - } - }, + entry: "./src/index.ts", + module: { + rules: [ + { + test: /\.ts$/, + use: ["ts-loader"] + }, + { + test: /\.wasm$/, + type: "asset/inline" + } + ] + }, + optimization: { + // the consuming project should take care of minification + minimize: false + }, + resolve: { + extensions: [".ts"], + alias: { + root: __dirname, + src: path.resolve(__dirname, "src") + } + }, output: { path: path.resolve(__dirname, "dist"), filename: "index.js", - libraryTarget: "commonjs2" + libraryTarget: "module" + }, + experiments: { + outputModule: true }, }; - \ No newline at end of file diff --git a/scripts/dev-website.sh b/scripts/dev-website.sh index e49bdb4..5c54cb8 100755 --- a/scripts/dev-website.sh +++ b/scripts/dev-website.sh @@ -2,13 +2,11 @@ set -e -rm -rf pkg - wasm-pack build --target web --features wasm +cd reconcile-js +npm run build +cp -R dist ../examples/website -cp -R pkg/reconcile.js examples/website/ -cp -R pkg/reconcile_bg.wasm examples/website/ - -cd examples/website/ +cd ../examples/website python3 -m http.server $1 --bind 0.0.0.0