-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
42 lines (39 loc) · 1.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
/* eslint-disable */
const fs = require('fs');
const path = require('path');
const ps = require('child_process');
const config = './config/webpack.' + process.env.ENV + '.js';
if (!fs.existsSync(config)) {
throw Error('The ENV variable points to your webpack config. ' + config + ' does not exist.');
}
const websiteConfig = require(process.env.WEBSITE_CONFIG && fs.existsSync(process.env.WEBSITE_CONFIG)
? process.env.WEBSITE_CONFIG
: './config/vpdb.' + process.env.CONFIG + '.json');
const buildConfig = require(process.env.BUILD_CONFIG && fs.existsSync(process.env.BUILD_CONFIG)
? process.env.BUILD_CONFIG
: './config/build.prod.json');
const firebaseConfig = require(process.env.FIREBASE_CONFIG && fs.existsSync(process.env.FIREBASE_CONFIG)
? process.env.FIREBASE_CONFIG
: './config/firebase.' + process.env.CONFIG + '.json');
const outputPath = path.resolve(__dirname, 'dist');
module.exports = require(config)({
env: process.env.ENV,
outputPath: outputPath,
websiteUrl: getUrl(websiteConfig.webUri),
apiUrl: getUrl(websiteConfig.apiUri),
storageUrl: getUrl(websiteConfig.storageUri),
previewUrl: getUrl(websiteConfig.previewUri),
websiteConfig: websiteConfig,
buildConfig: buildConfig,
firebaseConfig: firebaseConfig,
revision: getRevision()
});
function getUrl(site) {
return site.protocol + '://' + site.hostname + ([80, 443].includes(site.port) ? '' : ':' + site.port) + (site.pathname ? site.pathname : '') + '/';
}
function getRevision() {
return {
hash: ps.execSync('git rev-parse HEAD').toString().trim(),
date: new Date(ps.execSync('git log -1 --format=%cd').toString().trim()),
}
}