This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
forked from edrlab/thorium-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config-preprocessor-directives.js
84 lines (66 loc) · 2.95 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
80
81
82
83
84
const webpack = require("webpack");
const { version, build } = 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.TRAVIS_OS_NAME_ ? true : false;
const skipLevelDown = isDev || isContinuousIntegrationDeploy;
const pouchDbAdapterName = skipLevelDown ?
"websql" : // "jsondown"
"leveldb";
const pouchDbAdapterPackage = skipLevelDown ?
"pouchdb-adapter-node-websql" : ///"readium-desktop/pouchdb/jsondown-adapter" :
"pouchdb-adapter-leveldb";
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";
// const USE_HTTP_STREAMER = false;
const data = {
__APP_VERSION__: JSON.stringify(version),
__APP_NAME__: JSON.stringify(build.productName),
__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),
__POUCHDB_ADAPTER_NAME__: JSON.stringify(pouchDbAdapterName),
__POUCHDB_ADAPTER_PACKAGE__: JSON.stringify(pouchDbAdapterPackage),
__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),
// __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,
};