Closed FishOrBear closed 2 years ago
Did you try the universal version or the web one? If you tried the web version, could you try the universal?
I use this library in WebWorker in webpage, this is my current solution because Document is accessed in the code.
import * as clipperLib from "js-angusj-clipper/web";
export let clipperCpp: { lib?: clipperLib.ClipperLibWrapper; } = {};
export function InitClipperCpp(): Promise<void>
{
if (clipperCpp.lib) return;
if (!globalThis.document)
globalThis.document = {} as any;
return new Promise((res, rej) =>
{
clipperLib.loadNativeClipperLibInstanceAsync(
// let it autodetect which one to use, but also available WasmOnly and AsmJsOnly
clipperLib.NativeClipperLibRequestedFormat.WasmWithAsmJsFallback
).then(c =>
{
clipperCpp.lib = c;
res();
});
});
}
I think if you try the /universal one it should work without any workaround. The web version was only done for somebody saying that the universal version didn't work for angular in server side rendering mode: https://github.com/xaviergonz/js-angusj-clipper/issues/2
Just to clarify, to use universal it would mean removing /web from the import
import * as clipperLib from "js-angusj-clipper"; // instead of js-angusj-clipper/web
Since v1.2.0 it now uses emscripten module mode, which does not try to use process/document (AFAIK). Feel free to give it a try
Such code is already available.
export let clipperCpp: { lib?: clipperLib.ClipperLibWrapper; } = {};
export function InitClipperCpp(): Promise<void>
{
if (clipperCpp.lib) return;
return new Promise((res, rej) =>
{
clipperLib.loadNativeClipperLibInstanceAsync(
// let it autodetect which one to use, but also available WasmOnly and AsmJsOnly
clipperLib.NativeClipperLibRequestedFormat.WasmWithAsmJsFallback
).then(c =>
{
clipperCpp.lib = c;
res();
console.log("载入成功!");
});
});
}
However, this code cannot be used, and an error will occur. in web,webpack
import * as clipperLib from "js-angusj-clipper";
Error:
Module not found: Can't resolve 'path' in 'E:\WebProject\node_modules\js-angusj-clipper\universal\wasm'
node_modules/js-angusj-clipper/universal/wasm/clipper-wasm.js
/web/wasm/clipper.js /web/wasm/clipper-wasm.js
add line:
fix