1*c8dee2aaSAndroid Build Coastguard WorkerA WASM version of Skia's PathOps toolkit. 2*c8dee2aaSAndroid Build Coastguard Worker 3*c8dee2aaSAndroid Build Coastguard WorkerTo use the library, run `npm install pathkit-wasm` and then simply include it: 4*c8dee2aaSAndroid Build Coastguard Worker 5*c8dee2aaSAndroid Build Coastguard Worker <script src="/node_modules/pathkit-wasm/bin/pathkit.js"></script> 6*c8dee2aaSAndroid Build Coastguard Worker PathKitInit({ 7*c8dee2aaSAndroid Build Coastguard Worker locateFile: (file) => '/node_modules/pathkit-wasm/bin/'+file, 8*c8dee2aaSAndroid Build Coastguard Worker }).then((PathKit) => { 9*c8dee2aaSAndroid Build Coastguard Worker // Code goes here using PathKit 10*c8dee2aaSAndroid Build Coastguard Worker }); 11*c8dee2aaSAndroid Build Coastguard Worker 12*c8dee2aaSAndroid Build Coastguard WorkerPathKit comes in two parts, a JS loader and the actual WASM code. The JS loader creates 13*c8dee2aaSAndroid Build Coastguard Workera global `PathKitInit` that can be called to load the WASM code. The `locateFile` function 14*c8dee2aaSAndroid Build Coastguard Workeris used to tell the JS loader where to find the .wasm file. By default, it will 15*c8dee2aaSAndroid Build Coastguard Workerlook for /pathkit.wasm, so if this is not the case, use `locateFile` to configure 16*c8dee2aaSAndroid Build Coastguard Workerthis properly. 17*c8dee2aaSAndroid Build Coastguard WorkerThe `PathKit` object returned upon resolution of the PathKitInit Promise is fully loaded and ready to use. 18*c8dee2aaSAndroid Build Coastguard Worker 19*c8dee2aaSAndroid Build Coastguard WorkerSee the [API page](https://skia.org/user/modules/pathkit) and 20*c8dee2aaSAndroid Build Coastguard Worker[example.html](https://github.com/google/skia/blob/main/modules/pathkit/npm-wasm/example.html) 21*c8dee2aaSAndroid Build Coastguard Workerfor details on how to use the library. 22*c8dee2aaSAndroid Build Coastguard Worker 23*c8dee2aaSAndroid Build Coastguard WorkerUsing PathKit and WebPack 24*c8dee2aaSAndroid Build Coastguard Worker------------------------- 25*c8dee2aaSAndroid Build Coastguard Worker 26*c8dee2aaSAndroid Build Coastguard WorkerWebPack's support for WASM is still somewhat experimental, but PathKit can be 27*c8dee2aaSAndroid Build Coastguard Workerused with a few configuration changes. 28*c8dee2aaSAndroid Build Coastguard Worker 29*c8dee2aaSAndroid Build Coastguard WorkerIn the JS code, use require(): 30*c8dee2aaSAndroid Build Coastguard Worker 31*c8dee2aaSAndroid Build Coastguard Worker const PathKitInit = require('pathkit-wasm/bin/pathkit.js') 32*c8dee2aaSAndroid Build Coastguard Worker PathKitInit().then((PathKit) => { 33*c8dee2aaSAndroid Build Coastguard Worker // Code goes here using PathKit 34*c8dee2aaSAndroid Build Coastguard Worker }) 35*c8dee2aaSAndroid Build Coastguard Worker 36*c8dee2aaSAndroid Build Coastguard WorkerSince WebPack does not expose the entire `/node_modules/` directory, but instead 37*c8dee2aaSAndroid Build Coastguard Workerpackages only the needed pieces, we have to copy pathkit.wasm into the build directory. 38*c8dee2aaSAndroid Build Coastguard WorkerOne such solution is to use [CopyWebpackPlugin](https://github.com/webpack-contrib/copy-webpack-plugin). 39*c8dee2aaSAndroid Build Coastguard WorkerFor example, add the following plugin: 40*c8dee2aaSAndroid Build Coastguard Worker 41*c8dee2aaSAndroid Build Coastguard Worker config.plugins.push( 42*c8dee2aaSAndroid Build Coastguard Worker new CopyWebpackPlugin([ 43*c8dee2aaSAndroid Build Coastguard Worker { from: 'node_modules/pathkit-wasm/bin/pathkit.wasm' } 44*c8dee2aaSAndroid Build Coastguard Worker ]) 45*c8dee2aaSAndroid Build Coastguard Worker ); 46*c8dee2aaSAndroid Build Coastguard Worker 47*c8dee2aaSAndroid Build Coastguard WorkerIf webpack gives an error similar to: 48*c8dee2aaSAndroid Build Coastguard Worker 49*c8dee2aaSAndroid Build Coastguard Worker ERROR in ./node_modules/pathkit-wasm/bin/pathkit.js 50*c8dee2aaSAndroid Build Coastguard Worker Module not found: Error: Can't resolve 'fs' in '...' 51*c8dee2aaSAndroid Build Coastguard Worker 52*c8dee2aaSAndroid Build Coastguard WorkerThen, add the following configuration change to the node section of the config: 53*c8dee2aaSAndroid Build Coastguard Worker 54*c8dee2aaSAndroid Build Coastguard Worker config.node = { 55*c8dee2aaSAndroid Build Coastguard Worker fs: 'empty' 56*c8dee2aaSAndroid Build Coastguard Worker }; 57