webcrypto icon indicating copy to clipboard operation
webcrypto copied to clipboard

Add support for Webpack's NodeJS targets

Open ryan-codingintrigue opened this issue 7 years ago • 0 comments

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

ryan-codingintrigue avatar Jan 16 '19 08:01 ryan-codingintrigue