-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack-extensions.js
44 lines (39 loc) · 1.27 KB
/
webpack-extensions.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
34
35
36
37
38
39
40
41
42
43
44
const path = require("path");
const npmPackageConfig = require('./package.json')
const ReplaceInFileWebpackPlugin = require("replace-in-file-webpack-plugin");
// This helps in obtaining a timestamp based version string for local development.
const VersionStringReplacer = (dir, files) => {
const version = npmPackageConfig.version;
const versionComponents = version.split('.');
const major =versionComponents[0];
const minor =versionComponents[1];
const patch =versionComponents[2];
console.log(`Version: ${version} - major:${major},minor:${minor},patch:${patch}`);
return new ReplaceInFileWebpackPlugin([
{
dir,
files,
rules: [
{
search: /{{version}}/ig,
replace: version
},
{
search: /({{major}}|\"{{major}}\")/ig,
replace: major
},
{
search: /({{minor}}|\"{{minor}}\")/ig,
replace: minor
},
{
search: /({{patch}}|\"{{patch}}\")/ig,
replace: patch
}
]
}
]);
};
module.exports = {
VersionStringReplacer
}