-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
111 lines (99 loc) · 3.63 KB
/
webpack.config.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const ReplaceInFileWebpackPlugin = require("replace-in-file-webpack-plugin");
const WebpackCommon = require("./webpack.common.config");
const Target = WebpackCommon.GetTargetPath();
const Settings = {
"production": {
Tag: "",
TaskGuid: "{{guid_production}}",
},
"development": {
Tag: "Dev",
TaskGuid: "{{guid_development}}",
}
// Can add more flavors here as needed. For example, a flavor for pre-production
};
module.exports = env => {
const validEnvs = Object.keys(Settings);
if (!validEnvs.includes(env)) {
console.error(`BUILD_ENV not set correctly. Allowed values are: ${validEnvs.join(", ")}`);
process.exit(1);
}
const config = {
entry: {
"main": "./src/custom-task/main.ts",
},
plugins: [
new CopyWebpackPlugin([
// These files are needed by azure-pipelines-task-lib library.
{
from: path.resolve("./node_modules/azure-pipelines-task-lib/lib.json"),
to: path.join(Target, "custom-task")
},
{
from: path.resolve("./node_modules/azure-pipelines-task-lib/Strings"),
to: path.join(Target, "custom-task")
},
{
from: path.join(__dirname, "./src/custom-task/task.json"),
to: path.join(Target, "custom-task")
},
{
from: path.join(__dirname, "./images/icon.png"),
to: path.join(Target, "custom-task", "icon.png")
},
{
from: path.join(__dirname, "./manifests/base.json"),
to: Target
},
{
from: path.join(__dirname, "./manifests", `${env}.json`),
to: Target
},
{
from: path.join(__dirname, "./images/icon.png"),
to: Target
},
{
from: path.join(__dirname, "./src/README.md"),
to: Target
}
]),
WebpackCommon.PackageJsonLoadFixer(Target, [
"custom-task/main.js",
]),
WebpackCommon.VersionStringReplacer(Target, [
"custom-task/task.json",
"base.json"
]),
new ReplaceInFileWebpackPlugin([
{
dir: Target,
files: [
"custom-task/main.js",
"custom-task/task.json",
"base.json"
],
rules: [
// This replacement is required to allow azure-pipelines-task-lib to load the
// json resource file correctly
{
search: /__webpack_require__\(.*\)\(resourceFile\)/,
replace: 'require(resourceFile)'
},
{
search: /{{taskid}}/ig,
replace: Settings[env].TaskGuid
},
{
search: /{{tag}}/ig,
replace: Settings[env].Tag
}
]
}
])
],
};
return WebpackCommon.FillDefaultNodeSettings(config, env, "custom-task");
};