I'm creating a web based chat app using react and decided to implement end to end encryption. So I'm using signal encryption protocol. Now the main library I need to import in order to do end to end encryption is in a file called libsignal-protocol.js (it is available in signals github repo). All functions and variables I need to use is inside a variable called libsignal (example - libsignal.KeyHelper.generateIdentityKeyPair().
Library libsignal-protocol.js doesn't provide javascript modules so I'm importing whole library with a global script declaration.
<!DOCTYPE html>
<html lang="en">
<head>
<script src="libsignal-protocol.js"></script>
...........
</head>
<body>
......
</body>
</html>
Since my chat app is a react app, I tried to call libsignal's functions inside react components.
Webpack gives an error
Line 33:13: 'libsignal' is not defined no-undef
I googled and tried to solve this issue and found a very similar question but that question is related with typescript and I'm using javascript so this is not a duplicate.
Javascript doesn't have a declare keyword. How do I tell webpack that I have already imported libsignal using a global script tag?
window.whateverLibSignalAddsToGlobal. alternatively you can load the script asynchronously, and render your react tree / component afterwards github.com/eldargab/load-script