-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
85 lines (79 loc) · 2.12 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
const PACKAGE = require('./package.json');
const execSync = require('child_process').execSync;
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
class GitBanner {
apply(compiler) {
const envsVarToCheck = ['TEST_VAR', 'TEST_VAR2'] // put your env var list here
envsVarToCheck.forEach(envVar => {
if (!!!process.env[envVar]) {
throw new Error(`Environment variable : ${envVar} is missing`);
}
});
}
};
function git(args) {
return execSync(`git ${args}`).toString().trim();
}
function getBanner(dev) {
let banner = `${PACKAGE.name}, version: `;
try {
git("status");
} catch {
// no git repo, so do the best one can do
return banner + `${PACKAGE.version.replace("v", "")} with possible modifications`;
}
if (dev) {
banner += `dev${git("describe --dirty").replace("v", "")} ${git("branch --show-current")}`;
} else {
let errors = [];
if (git("diff-files")) {
errors.push("Production build cannot have uncommitted modifications.")
}
try {
banner += git("describe --exact-match HEAD").replace("v", "");
} catch {
errors.push("A git tag matching current HEAD is required.")
}
if (errors.length > 0) {
for (error of errors) {
console.error(error);
}
throw new Error("production build not possible");
}
}
return `${banner}\nLicense: GNU Affero General Public License v3 or later`;
}
module.exports = (env, argv) => {
const dev = argv.mode === "development";
banner = getBanner(dev);
return {
entry: './build/index.js',
resolve: {
extensions: [ '.tsx', '.ts', '.js' ]
},
stats: {
all: false,
assets: true,
errors: true,
},
optimization: {
minimize: !dev,
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
},
output: {
filename: `antismash${dev ? "_dev" : ""}.js`,
libraryTarget: 'var',
library: 'viewer',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new webpack.BannerPlugin(banner),
]
};
}