Skip to content

Commit ce1556c

Browse files
authored
Merge pull request #187 from BeAPI/chore/webpack-sprite-hash-plugin
chore(build): avoid redundant sprite hash file writes
2 parents bfe2d09 + 87549ec commit ce1556c

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎config/webpack-sprite-hash-plugin.js‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,21 @@ class SpriteHashPlugin {
101101
'return ' + this.formatPhpArray(hashes) + ';',
102102
'',
103103
];
104-
fs.writeFileSync(outputFile, phpLines.join('\n'));
104+
const nextContent = phpLines.join('\n');
105+
106+
if (
107+
fs.existsSync(outputFile) &&
108+
fs.readFileSync(outputFile, 'utf8') === nextContent
109+
) {
110+
callback();
111+
return;
112+
}
113+
114+
fs.writeFileSync(outputFile, nextContent);
105115

106116
// eslint-disable-next-line no-console
107117
console.log(
108-
`SpriteHashPlugin: Generated ${
109-
this.options.outputFilename
118+
`SpriteHashPlugin: Generated ${this.options.outputFilename
110119
} with ${Object.keys(hashes).length} sprites`
111120
);
112121

0 commit comments

Comments
 (0)