-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathCustomVersionFilePlugin.js
33 lines (31 loc) · 1.17 KB
/
CustomVersionFilePlugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const fs = require('fs');
const path = require('path');
const APP_VERSION = require('../../package.json').version;
/**
* Simple webpack plugin that writes the app version (from package.json) and the webpack hash to './version.json'
*/
class CustomVersionFilePlugin {
apply(compiler) {
compiler.hooks.done.tap(
this.constructor.name,
() =>
new Promise((resolve, reject) => {
const versionPath = path.join(__dirname, '/../../dist/version.json');
fs.mkdir(path.dirname(versionPath), {recursive: true}, (dirErr) => {
if (dirErr) {
reject(dirErr);
return;
}
fs.writeFile(versionPath, JSON.stringify({version: APP_VERSION}), 'utf8', (fileErr) => {
if (fileErr) {
reject(fileErr);
return;
}
resolve();
});
});
}),
);
}
}
module.exports = CustomVersionFilePlugin;