anvilresearch / webcrypto

W3C Web Cryptography API for Node.js
MIT License
82 stars 14 forks source link

Add support for Webpack's NodeJS targets #84

Open ryan-codingintrigue opened 5 years ago

ryan-codingintrigue commented 5 years ago

I know the README says Not for use in Webpack, but Webpack isn't only used for outputting browser code. When using a target other than web (NodeJS, Electron, etc.) there's no reason this library shouldn't be able to be bundled using Webpack too.

The reason it doesn't work is because of this block of code:

https://github.com/anvilresearch/webcrypto/blob/5303c62ac2f0c0cef293d9a8d3d54e0b794149aa/src/algorithms/SupportedAlgorithms.js#L84

Webpack doesn't handle dynamic require very well.

This PR addresses the issue by turning the registeredAlgorithms into a factory function, rather than a path, allowing Webpack to effectively track which files should be bundled. This will allow users to use Webpack for any NodeJS target