diff --git a/reconcile-js/src/index.ts b/reconcile-js/src/index.ts index a0d488f..6db3163 100644 --- a/reconcile-js/src/index.ts +++ b/reconcile-js/src/index.ts @@ -1,4 +1,4 @@ -import wasmInit, { +import { CursorPosition as wasmCursorPosition, reconcile as wasmReconcile, TextWithCursors as wasmTextWithCursors, @@ -9,7 +9,7 @@ import wasmInit, { initSync, } from 'reconcile'; -import wasm from 'reconcile/reconcile_bg.wasm'; +import wasmBytes from 'reconcile/reconcile_bg.wasm'; export interface TextWithCursors { /** The document's entire content */ @@ -131,7 +131,10 @@ function init() { return; } - initSync({ module: (wasm as any).default }); + const wasmBinary = Uint8Array.from(atob(wasmBytes as unknown as string), (c) => + c.charCodeAt(0) + ); + initSync({ module: wasmBinary }); isInitialised = true; } diff --git a/reconcile-js/webpack.config.js b/reconcile-js/webpack.config.js index 28fed8c..bf126fa 100644 --- a/reconcile-js/webpack.config.js +++ b/reconcile-js/webpack.config.js @@ -3,18 +3,6 @@ const { merge } = require('webpack-merge'); const common = { 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, @@ -27,7 +15,25 @@ const common = { }, }, performance: { - hints: false, // it's a library, no need to warn about its size + hints: false, + }, + experiments: { + asyncWebAssembly: true, + }, + module: { + rules: [ + { + test: /\.ts$/, + use: ['ts-loader'], + }, + { + test: /\.wasm$/, + type: 'asset/inline', + generator: { + dataUrl: (content) => content.toString('base64'), + }, + }, + ], }, };