-
Notifications
You must be signed in to change notification settings - Fork 31
/
webpack.config.js
113 lines (104 loc) · 3.74 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
'use strict';
var webpack = require('webpack');
const HTMLWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var colors = require('colors');
const dhisConfigPath = process.env.DHIS2_HOME && `${process.env.DHIS2_HOME}/config.json`;
let dhisConfig;
try {
dhisConfig = require(dhisConfigPath);
console.log('\nLoaded DHIS config:');
} 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/dhis',
authorization: 'Basic YWRtaW46ZGlzdHJpY3Q=' // admin:district
};
}
console.log(JSON.stringify(dhisConfig, null, 2), '\n');
function bypass(req, res, opt) {
req.headers.Authorization = dhisConfig.authorization;
}
function makeLinkTags(stylesheets) {
return function (hash) {
return stylesheets
.map(([url, attributes]) => {
const attributeMap = Object.assign({ media: 'screen' }, attributes);
const attributesString = Object
.keys(attributeMap)
.map(key => `${key}="${attributeMap[key]}"`)
.join(' ');
return `<link type="text/css" rel="stylesheet" href="${url}?_=${hash}" ${attributesString} />`;
})
.join(`\n`);
};
}
function makeScriptTags(scripts) {
return function (hash) {
return scripts
.map(script => (`<script src="${script}?_=${hash}"></script>`))
.join(`\n`);
};
}
module.exports = {
context: __dirname,
entry: './scripts/index.js',
output: {
path: path.join(__dirname, '/build'),
filename: 'app-[hash].js'
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: [/(node_modules)/],
loaders: ['ng-annotate-loader', 'babel-loader'],
},
{
test: /\.css$/,
loader: 'style-loader!css-loader'
},
{
test: /\.(gif|png|jpg|svg)$/,
loader: 'file-loader'
},
],
noParse: /node_modules\/leaflet-control-geocoder\/dist\/Control.Geocoder.js/,
},
plugins: [
new webpack.optimize.DedupePlugin(),
new HTMLWebpackPlugin({
template: './index.ejs',
stylesheets: makeLinkTags([
['styles/style.css'],
['styles/print.css', { media: 'print' }],
]),
scripts: makeScriptTags([
'core/tracker-capture.js',
'vendor/main/main.js',
]),
}),
],
devtool: 'sourcemap',
devServer: {
contentBase: '.',
progress: true,
colors: true,
port: 8081,
inline: false,
compress: false,
proxy: [
{ path: '/api/**', target: dhisConfig.baseUrl, bypass:bypass },
{ path: '/dhis/dhis-web-commons/**', target: dhisConfig.baseUrl, bypass:bypass},
{ path: '/dhis-web-commons-ajax-json/**', target: dhisConfig.baseUrl, bypass:bypass },
{ path: '/dhis-web-commons-stream/**', target: dhisConfig.baseUrl, bypass:bypass },
{ path: '/dhis-web-commons/***', target: dhisConfig.baseUrl, bypass:bypass, proxyTimeout: 1000 * 60 * 5 },
{ path: '/dhis-web-core-resource/**', target: dhisConfig.baseUrl, bypass:bypass },
{ path: '/icons/**', target: dhisConfig.baseUrl, bypass:bypass },
{ path: '/images/**', target: dhisConfig.baseUrl, bypass:bypass },
{ path: '/main.js', target: dhisConfig.baseUrl, bypass:bypass },
],
},
};