Add short hash when serving bundles
This commit is contained in:
parent
8f9d80acbe
commit
1ace0b3156
3 changed files with 15 additions and 1 deletions
6
package-lock.json
generated
6
package-lock.json
generated
|
@ -7650,6 +7650,12 @@
|
||||||
"integrity": "sha512-6qE4B9deFBIa9YSpOc9O0Sgc43zTeVYbgDT5veRKSlB2+ZuHNoVVxA1L/ckMUayV9Ay9y7Z/SZCLcGteW9i7bg==",
|
"integrity": "sha512-6qE4B9deFBIa9YSpOc9O0Sgc43zTeVYbgDT5veRKSlB2+ZuHNoVVxA1L/ckMUayV9Ay9y7Z/SZCLcGteW9i7bg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"md5-file": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/md5-file/-/md5-file-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-UC0qFwyAjn4YdPpKaDNw6gNxRf7Mcx7jC1UGCY4boCzgvU2Aoc1mOGzTtrjjLKhM5ivsnhoKpQVxKPp+1j1qwg==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"md5.js": {
|
"md5.js": {
|
||||||
"version": "1.3.5",
|
"version": "1.3.5",
|
||||||
"resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz",
|
"resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz",
|
||||||
|
|
|
@ -104,6 +104,7 @@
|
||||||
"file-loader": "^2.0.0",
|
"file-loader": "^2.0.0",
|
||||||
"har-validator": "^5.1.3",
|
"har-validator": "^5.1.3",
|
||||||
"husky": "^1.1.3",
|
"husky": "^1.1.3",
|
||||||
|
"md5-file": "^4.0.0",
|
||||||
"mini-css-extract-plugin": "^0.5.0",
|
"mini-css-extract-plugin": "^0.5.0",
|
||||||
"mocha": "^5.2.0",
|
"mocha": "^5.2.0",
|
||||||
"ndb": "^1.0.26",
|
"ndb": "^1.0.26",
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
const md5File = require('md5-file');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const bundlePath = path.resolve('./public/bundle/bundle.js');
|
||||||
|
const bundleHash = md5File.sync(bundlePath);
|
||||||
|
const shortBundleHash = bundleHash.substring(0,4);
|
||||||
|
|
||||||
module.exports = (helmet, html, preloadedState) => {
|
module.exports = (helmet, html, preloadedState) => {
|
||||||
// take the html and preloadedState and return the full page
|
// take the html and preloadedState and return the full page
|
||||||
return `
|
return `
|
||||||
|
@ -22,7 +29,7 @@ module.exports = (helmet, html, preloadedState) => {
|
||||||
<script>
|
<script>
|
||||||
window.__PRELOADED_STATE__ = ${JSON.stringify(preloadedState).replace(/</g, '\\\u003c')}
|
window.__PRELOADED_STATE__ = ${JSON.stringify(preloadedState).replace(/</g, '\\\u003c')}
|
||||||
</script>
|
</script>
|
||||||
<script src="/bundle/bundle.js"></script>
|
<script src="/bundle/bundle.js?${shortBundleHash}"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
`;
|
`;
|
||||||
|
|
Loading…
Reference in a new issue