-
Notifications
You must be signed in to change notification settings - Fork 159
/
webpack.config-preprocessor-directives.js
79 lines (63 loc) · 3.05 KB
/
webpack.config-preprocessor-directives.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
const webpack = require("webpack");
const { version, build, name } = require("./package.json");
// var git = require("git-rev-sync");
const portApp = process.env.PORT_APP || "8090";
const portReader = process.env.PORT_READER || "8191";
const portPdfWebview = process.env.PORT_PDF_WEBVIEW || "8292";
// Get node environment
const nodeEnv = process.env.NODE_ENV || "development";
console.log(`PREPROCESSOR nodeEnv: ${nodeEnv}`);
const isDev = nodeEnv === "development";
const isVisualStudioCodeLaunch = process.env.VSCODE_LAUNCH || "false";
const isContinuousIntegrationDeploy = process.env.GITHUB_TOKEN_RELEASE_PUBLISH ? true : false;
const rendererLibraryBaseUrl = isDev ? "http://localhost:" + portApp + "/" : "file://";
const rendererReaderBaseUrl = isDev ? "http://localhost:" + portReader + "/" : "file://";
const rendererPdfWebviewBaseUrl = isDev ? "http://localhost:" + portPdfWebview + "/" : "file://";
const isPackaging = process.env.PACKAGING || "0";
const nodeModuleRelativeUrl = isPackaging === "1" ? "node_modules" : "../node_modules";
const distRelativeUrl = isPackaging === "1" ? "dist" : "../dist";
// "http://localhost:8080/";
// MUST END WITH FORWARD SLASH!
const telemetryUrl =
isPackaging === "1"
? process.env.THORIUM_TELEMETRY_URL ||
(isContinuousIntegrationDeploy ? "https://telemetry-staging.edrlab.org/" : "https://telemetry.edrlab.org/")
: "";
const telemetrySecret = process.env.THORIUM_TELEMETRY_SECRET || "";
// const USE_HTTP_STREAMER = false;
const data = {
__APP_VERSION__: JSON.stringify(version),
__PACK_NAME__: JSON.stringify(name), // EDRLab.ThoriumReader
__APP_NAME__: JSON.stringify(build.productName), // Thorium
// __GIT_BRANCH__: JSON.stringify(git.branch()),
// __GIT_DATE__: JSON.stringify(git.date()),
// __GIT_SHORT__: JSON.stringify(git.short()),
__NODE_ENV__: JSON.stringify(nodeEnv),
__VSCODE_LAUNCH__: JSON.stringify(isVisualStudioCodeLaunch),
__NODE_MODULE_RELATIVE_URL__: JSON.stringify(nodeModuleRelativeUrl),
__DIST_RELATIVE_URL__: JSON.stringify(distRelativeUrl),
__PACKAGING__: JSON.stringify(isPackaging),
__RENDERER_LIBRARY_BASE_URL__: JSON.stringify(rendererLibraryBaseUrl),
__RENDERER_READER_BASE_URL__: JSON.stringify(rendererReaderBaseUrl),
__RENDERER_PDF_WEBVIEW_BASE_URL__: JSON.stringify(rendererPdfWebviewBaseUrl),
__CONTINUOUS_INTEGRATION_DEPLOY__: JSON.stringify(isContinuousIntegrationDeploy),
__TELEMETRY_URL__: JSON.stringify(telemetryUrl),
__TELEMETRY_SECRET__: JSON.stringify(telemetrySecret),
// __USE_HTTP_STREAMER__: JSON.stringify(USE_HTTP_STREAMER),
};
// we do not replace "process.env.NODE_ENV" at build-time,
// because we check actual runtime env vars
// when __PACKAGING__ === "0" && __NODE_ENV__ === "PROD" (npm run start)
if (false) {
data["process.env.NODE_ENV"] = JSON.stringify(nodeEnv);
}
const definePlugin = new webpack.DefinePlugin(data);
module.exports = {
definePlugin,
portApp,
portReader,
portPdfWebview,
rendererLibraryBaseUrl,
rendererReaderBaseUrl,
rendererPdfWebviewBaseUrl,
};