Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using PathKit with Webpack 5 (https://skia.org/docs/user/modules/pathkit/)

PathKit's docs are out of date, and changes in Webpack 5 mean that their installation instructions don't work

Install the following from NPM:

  • pathkit-wasm
  • webpack 5
  • copy-webpack-plugin
  • node-polyfill-webpack-plugin

Make sure your Webpack config has the following:

const CopyWebpackPlugin = require('copy-webpack-plugin');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');

module.exports = {
  ...
  resolve: {
    ...
    fallback: {
      'fs': false,
    }
  }
  ...
  plugins: [
    ...
    new NodePolyfillPlugin(),
    new CopyWebpackPlugin({
      patterns: [
        { from: 'node_modules/pathkit-wasm/bin/pathkit.wasm', to: 'pathkit.wasm' }
      ]
    })
  ]
}

And then in your JS:

const PathKitInit = require('pathkit-wasm');

(async () => {

  const PathKit = await PathKitInit({ locateFile: (file) => `./${file}` });
  // use pathkit here!

})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment