Skip to content

Instantly share code, notes, and snippets.

@matthlavacka
Created February 2, 2017 13:43
Show Gist options
  • Save matthlavacka/ac348ac6fa139491bb5b1b92c4e8cca9 to your computer and use it in GitHub Desktop.
Save matthlavacka/ac348ac6fa139491bb5b1b92c4e8cca9 to your computer and use it in GitHub Desktop.
function () {
this.plugin("done", function (stats) {
var replaceInFile = function (filePath, toReplace, replacement) {
var replacer = function (match) {
console.log('Replacing in %s: %s => %s', filePath, match, replacement);
return replacement
};
var str = fs.readFileSync(filePath, 'utf8');
var out = str.replace(new RegExp(toReplace, 'g'), replacer);
fs.writeFileSync(filePath, out);
};
var hash = stats.hash; // Build's hash, found in `stats` since build lifecycle is done.
replaceInFile(path.join(__dirname, '..', 'app', 'pages', 'assets.js'),
'main.[^.]*.css',
`main.${hash}.css`
);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment