Skip to content

Commit

Permalink
Add hash to bundle.js to break caching on change
Browse files Browse the repository at this point in the history
  • Loading branch information
gotdan committed Apr 30, 2017
1 parent 41cc1e7 commit 6fd1ad1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"jsx-loader": "^0.13.2",
"mocha": "^2.3.3",
"webpack": "^1.12.2",
"webpack-dev-server": "^1.12.0"
"webpack-dev-server": "^1.12.0",
"webpack-file-changer": "^2.0.1"
},
"dependencies": {
"freezer-js": "^0.8.0",
Expand Down
2 changes: 1 addition & 1 deletion public/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ span.fhir-element-value {
.footer {
padding-top: 10px;
border-top: 2px solid #317eac;
margin-top: 20px;
margin-top: 40px;
text-align: center;
}

Expand Down
3 changes: 2 additions & 1 deletion public/bundle.js → public/bundle.aada187d50d6db0545c2.js
Original file line number Diff line number Diff line change
Expand Up @@ -69463,7 +69463,8 @@
"jsx-loader": "^0.13.2",
"mocha": "^2.3.3",
"webpack": "^1.12.2",
"webpack-dev-server": "^1.12.0"
"webpack-dev-server": "^1.12.0",
"webpack-file-changer": "^2.0.1"
},
"dependencies": {
"freezer-js": "^0.8.0",
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@

<script src="./vendor/jquery-2.1.4.min.js"></script>
<script src="./vendor/FileSaver.min.js"></script>
<script src="bundle.js"></script>
<script src="bundle.aada187d50d6db0545c2.js"></script>
</div></body>
</html>
36 changes: 35 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
var FileChanger = require("webpack-file-changer");
var fs = require("fs");
var path = require("path");

getPlugins = function() {
if (process.env.WEBPACK_ENV != 'build') return;

var fileChangerOptions = {
change: [{
file: './public/index.html',
parameters: {
'bundle\.(.+)\.js': 'bundle.[renderedHash:0].js'
},
// delete all but most recent bundle
before: function(stats, change) {
var dir = './public/';
var files = fs.readdirSync(dir)
.filter(function (name) { return /bundle\.(.+)\.js/.test(name) } )
.sort(function(a, b) {
return fs.statSync(path.join(dir, b)).mtime.getTime() -
fs.statSync(path.join(dir, a)).mtime.getTime();
})
.forEach(function(name, i) {
if (i > 0) fs.unlinkSync(path.join(dir, name))
})
return true;
}
}]
};

return [ new FileChanger(fileChangerOptions) ]
};

module.exports = {
entry: './src/index.cjsx',
plugins: getPlugins(),
output: {
filename: (process.env.WEBPACK_ENV === 'build' ? './public/bundle.js' : 'bundle.js')
filename: (process.env.WEBPACK_ENV === 'build' ? './public/bundle.[chunkhash].js' : 'bundle.js')
},
module: {
loaders: [
Expand Down

0 comments on commit 6fd1ad1

Please sign in to comment.