forked from dhis2/maintenance-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
146 lines (134 loc) · 4.21 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
'use-strict';
const webpack = require('webpack');
const path = require('path');
const colors = require('colors');
const nodeEnv = process.env.NODE_ENV || 'development';
const isDevBuild = process.argv[1].indexOf('webpack-dev-server') !== -1;
const isProfileBuild = process.argv[1].indexOf('--profile') !== -1;
const dhisConfigPath = process.env.DHIS2_HOME && `${process.env.DHIS2_HOME}/config`;
const HTMLWebpackPlugin = require('html-webpack-plugin');
const Visualizer = require('webpack-visualizer-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
var dhisConfig;
try {
dhisConfig = require(dhisConfigPath);
console.log(dhisConfig);
} catch (e) {
// Failed to load config file - use default config
console.warn(`\nWARNING! Failed to load DHIS config:`, e.message);
console.info('Using default config');
dhisConfig = {
baseUrl: 'http://localhost:8080',
authorization: 'Basic YWRtaW46ZGlzdHJpY3Q=', // admin:district
};
}
// console.log(JSON.stringify(dhisConfig, null, 2), '\n');
function bypass(req, res, opt) {
req.headers.Authorization = dhisConfig.authorization;
console.log('[PROXY]'.cyan.bold, req.method.green.bold, req.url.magenta, '=>'.dim, opt.target.dim);
}
const scriptPrefix = (isDevBuild ? dhisConfig.baseUrl : '..');
const webpackConfig = {
context: __dirname,
performance: { hints: false },
entry: {
maintenance: './src/maintenance.js',
commons: ['babel-polyfill', 'material-ui', 'd2-utilizr'],
},
devtool: 'source-map',
output: {
path: __dirname + '/build',
filename: '[name]-[hash].js',
publicPath: isDevBuild ? 'http://localhost:8081/' : './',
},
module: {
loaders: [
{
test: /\.jsx?$/,
include: path.resolve(__dirname, 'src/'),
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
},
{
test: /\.css$/,
loader: 'style-loader!css-loader',
},
{
test: /\.scss$/,
loader: 'style-loader!css-loader!sass-loader',
},
{
test: /\.json$/,
loader: 'json-loader',
},
{
test: /\.(jpe|jpg|woff|woff2|eot|ttf|svg)(\?.*$|$)/,
loader: 'file-loader'
},
],
},
resolve: {
alias: {
d2: __dirname+'/node_modules/d2',
},
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: "commons",
filename: "commons-[hash].js",
}),
new webpack.DefinePlugin({
DHIS_CONFIG: isDevBuild ? JSON.stringify(dhisConfig) : {},
'process.env': { NODE_ENV: JSON.stringify(nodeEnv) }
}),
isDevBuild ? undefined : new webpack.LoaderOptionsPlugin({
minimize: false,
debug: true,
}),
new HTMLWebpackPlugin({
template: './index.ejs',
}),
isDevBuild ? undefined : new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
output: {
comments: false,
},
sourceMap: true,
}),
isProfileBuild ? new BundleAnalyzerPlugin() : undefined,
isProfileBuild ? new Visualizer : undefined,
].filter(v => v),
devServer: {
port: 8081,
inline: true,
compress: true,
watchOptions: {
aggregateTimeout: 2000,
},
proxy: [
{
context: [
'/api/**',
'/dhis-web-commons/**',
'/dhis-web-core-resource/**',
'/icons/**',
'/css/**',
'/images/**',
],
target: dhisConfig.baseUrl,
changeOrigin: true,
bypass,
},
{
path: '/i18n/**',
target: 'http://localhost:8081/src',
bypass,
},
],
},
};
module.exports = webpackConfig;