Use the following to hash your script and out the string needed for SRI.
echo -n "sha256-" && openssl dgst -sha256 -binary ./path/to/file.js | openssl base64 -A; echo
Use the following to load your script
<script defer src="./path/to/file.js" integrity="sha256-<hash>"></script>
Using scripts from another domain?
If using scripts from another domain such as a CDN you’ll need to include crossorigin="anonymous"
or the integrity check won’t be performed by the browser.
Use the following to load your script:
<script defer src="/assets/js/template-web.min.js" integrity="sha256-0sL5IkMJDqqdc9pElxsYupSMQjKt2+Ua6dCMPoDrwGg=" crossorigin="anonymous"></script>
Further reading
Check out the Wikipedia article and SRI Hash Generator