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!
})();