Skip to content

Instantly share code, notes, and snippets.

@jaames
Created July 7, 2021 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaames/b0cdc3b4c6850bc930f0a12a60c41369 to your computer and use it in GitHub Desktop.
Save jaames/b0cdc3b4c6850bc930f0a12a60c41369 to your computer and use it in GitHub Desktop.
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