You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #42 Add support for integrity hashes (Lyrkan)
This PR was squashed before being merged into the master branch (closes#42).
Discussion
----------
Add support for integrity hashes
This PR allows to automatically add `integrity` attributes on `<script>` and `<link>` tags based on the content of the `entrypoints.json` file (related to the following PR on Encore: symfony/webpack-encore#522).
It requires the following configuration:
```js
// webpack.config.js
// Enable it for all builds with the
// default hash algorithm (sha384)
Encore.enableIntegrityHashes();
// Or enable it only in production
// with a custom hash algorithm
Encore.enableIntegrityHashes(
Encore.isProduction(),
'sha384'
);
// Or with multiple hash algorithms
Encore.enableIntegrityHashes(
Encore.isProduction(),
['sha384','sha512']
);
```
Then, calling `yarn encore` then generates an entrypoints.json that contains hashes for all the files it references:
```js
{
"entrypoints": {
// (...)
},
"integrity": {
"/build/runtime.fa8f03f5.js": "sha384-5WSgDNxkAY6j6/bzAcp3v//+PCXLgXCU3u5QgRXWiRfMnN4Ic/a/EF6HJnbRXik8",
"/build/0.b70b772e.js": "sha384-FA3+8ecenjmV1Y751s0fKxGBNtyLBA8hDY4sqFoqvsCPOamLlA5ckhRBttBg1esp",
// (...)
}
}
```
And these hashes are automatically added when calling `encore_entry_script_tags` and `encore_entry_link_tags`:
```html
<html lang="en">
<head>
<!-- ... -->
<link rel="stylesheet" href="/build/css/app.2235bc2d.css" integrity="sha384-Jmd35HF93DFCXjisVeMi6U3lniH/mOdAF6wLtOMqhYMh2ZiBRUdtF7jXB55IAKfm">
<!-- ... -->
</head>
<body id="homepage">
<!-- ... -->
<script src="/build/runtime.fa8f03f5.js" integrity="sha384-5WSgDNxkAY6j6/bzAcp3v//+PCXLgXCU3u5QgRXWiRfMnN4Ic/a/EF6HJnbRXik8"></script>
<script src="/build/0.b70b772e.js" integrity="sha384-FA3+8ecenjmV1Y751s0fKxGBNtyLBA8hDY4sqFoqvsCPOamLlA5ckhRBttBg1esp"></script>
<!-- ... -->
</body>
</html>
```
An example using Symfony Demo can be found here: Lyrkan/symfony-demo@91a06cd
Commits
-------
84c41ed Add support for integrity hashes
0 commit comments