-
Notifications
You must be signed in to change notification settings - Fork 15
/
webpack.config.js
147 lines (142 loc) · 4.85 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
const path = require('path');
const webpack = require('webpack');
const WebpackGitHash = require('webpack-git-hash');
const fs = require('fs');
const pkg = require('./package.json');
const TerserPlugin = require('terser-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
// Import config file
let isAWS = process.env.NODE_TYPE == 'aws';
let _config = null;
if (isAWS) {
_config = require('./apache/config.json');
} else {
_config = require(process.env.SCOPE_CONFIG || './config.json');
}
if (process.env.SCOPE_PORT) {
_config.publicHostAddress += ':' + process.env.SCOPE_PORT;
console.log('Appending SCOPE_PORT to publicHostAddress');
}
console.log(_config);
let config = {
mode: process.env.NODE_ENV,
devtool: 'inline-source-map',
entry: './src/main.tsx',
devServer: {
host: '0.0.0.0',
port: _config.mPort,
disableHostCheck: true,
},
output: {
path: path.resolve('assets'),
// filename: 'main.js',
publicPath: '/assets/', // './assets/'
filename: pkg.name + '-' + pkg.version + '.[githash].js',
chunkFilename: pkg.name + '-chunk.[githash].js',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.css'],
},
module: {
rules: [
{
test: /\.(t|j)s(x?)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
babelrc: false,
presets: [
'@babel/preset-env',
'@babel/preset-typescript',
'@babel/preset-react',
],
plugins: [
[
'@babel/plugin-proposal-class-properties',
{ loose: true },
],
['@babel/plugin-proposal-object-rest-spread'],
['@babel/transform-runtime'],
],
},
},
],
},
{
test: /\.css$/,
loader: 'style-loader!css-loader',
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader?limit=100000',
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
NODE_TYPE: JSON.stringify(process.env.NODE_TYPE),
},
}),
new webpack.DefinePlugin({
DEBUG: _config.debug,
REVERSEPROXYON: _config.reverseProxyOn,
}),
new webpack.DefinePlugin({
BITLY: JSON.stringify({
baseURL: 'http://scope.aertslab.org',
token: '8422dd882b60604d327939997448dd1b5c61f54e',
}),
BACKEND: JSON.stringify({
httpProtocol: _config.httpProtocol,
wsProtocol: _config.wsProtocol,
host: _config.localHostAddress,
WSport: _config.xPort,
XHRport: _config.pPort,
RPCport: _config.gPort,
}),
FRONTEND: JSON.stringify({
httpProtocol: _config.httpProtocol,
wsProtocol: _config.wsProtocol,
host: _config.publicHostAddress,
}),
ORCID: JSON.stringify({
orcidAPIClientID: _config.orcidAPIClientID,
orcidAPIRedirectURI: _config.orcidAPIRedirectURI,
}),
}),
new WebpackGitHash({
cleanup: true,
callback: function (versionHash) {
let indexHtml = fs.readFileSync('./index.html', 'utf8');
indexHtml = indexHtml.replace(
/src="\.\/assets\/.*\.js"/,
'src="./assets/' +
pkg.name +
'-' +
pkg.version +
'.' +
versionHash +
'.js"'
);
fs.writeFileSync('./index.html', indexHtml);
},
}),
new ForkTsCheckerWebpackPlugin(),
],
};
if (process.env.NODE_ENV === 'production') {
config.plugins.push(new webpack.optimize.OccurrenceOrderPlugin());
config.optimization = {
minimize: true,
minimizer: [new TerserPlugin()],
};
} else {
config.plugins.push(new webpack.NamedModulesPlugin());
}
// config.node = { fs: 'empty', child_process: 'empty' };
module.exports = config;