这是 bootstrap 的官方 CDN 样式表:
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css"
integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B"
crossorigin="anonymous">
然而,在我的标记中,我没有对版本进行硬编码,因为它可能会改变,所以我将它从我的构建系统或应用程序中拉出来。一个虚构的例子:
<link rel="stylesheet" href="https://foo.bar.com/jquery/$VERSION/all.min.js" />
如您所见$VERSION
,它不是硬编码的。因此,我可以更改在构建过程中使用的版本(在 中package.json
),而不必编辑我的应用程序。
现在我想以integrity
同样的方式添加。我希望我能在 中找到它package.json
,但是对于 bootsrap 来说,它不存在。我也假设其他软件包。
我知道我可以这样计算:
echo -n "alert('Hello, world.');" | openssl dgst -sha384 -binary | openssl base64 -A
但我不想让我的构建系统过于复杂。
有没有什么地方可以得到这个值,而不必硬编码?我自动从我的项目package.json
(或 in node_modules/bootstrap
)中提取版本,因此我希望为完整性做类似的事情。