forked from HISPColombia/SharingSettingVer2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
132 lines (122 loc) · 4.36 KB
/
Copy pathwebpack.config.js
File metadata and controls
132 lines (122 loc) · 4.36 KB
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
'use strict';
const webpack = require('webpack');
const path = require('path');
const colors = require('colors');
const isDevBuild = process.argv[1].indexOf('webpack-dev-server') !== -1;
const dhisConfigPath = process.env.DHIS2_HOME && `${process.env.DHIS2_HOME}` && "/dhis.conf";
let dhisConfig;
try {
dhisConfig = require(dhisConfigPath);
} catch (e) {
// Failed to load config file - use default config
console.warn(`\nWARNING! Failed to load DHIS config:`, e.message);
dhisConfig = {
baseUrl: 'http://localhost:8080/dhis',
authorization: 'Basic YWRtaW46Q2xhdmUqMTIzNDU2', // admin:district
};
}
const HTMLWebpackPlugin = require('html-webpack-plugin');
const scriptPrefix = (isDevBuild ? dhisConfig.baseUrl : '..');
function log(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 webpackConfig = {
context: __dirname,
entry: './src/app.js',
devtool: 'source-map',
mode: 'development',
output: {
path: __dirname + '/build',
filename: 'sharingsetting.js',
publicPath: isDevBuild ? 'http://localhost:8081/' : './',
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
},
},
{
test: /\.css$/,
loader: 'style-loader!css-loader',
},
{
test: /\.scss$/,
loader: 'style-loader!css-loader!sass-loader',
},
],
},
resolve: {
alias: {
react: path.resolve('./node_modules/react'),
'material-ui': path.resolve('./node_modules/material-ui'),
},
},
externals: [
{
'react': 'var React',
'react-dom': 'var ReactDOM',
'react-addons-transition-group': 'var React.addons.TransitionGroup',
'react-addons-create-fragment': 'var React.addons.createFragment',
'react-addons-update': 'var React.addons.update',
'react-addons-pure-render-mixin': 'var React.addons.PureRenderMixin',
'react-addons-shallow-compare': 'var React.addons.ShallowCompare',
'rx': 'var Rx',
'lodash': 'var _',
},
/^react-addons/,
/^react-dom$/,
/^rx$/,
],
plugins: [
new HTMLWebpackPlugin({
template: './src/index.html',
vendorScripts: [
`${scriptPrefix}/dhis-web-core-resource/react-15/react-15${isDevBuild ? '' : '.min'}.js`,
`${scriptPrefix}/dhis-web-core-resource/rxjs/4.1.0/rx.all${isDevBuild ? '' : '.min'}.js`,
`${scriptPrefix}/dhis-web-core-resource/lodash/4.15.0/lodash${isDevBuild ? '' : '.min'}.js`,
]
.map(script => {
if (Array.isArray(script)) {
return (`<script ${script[1]} src="${script[0]}"></script>`);
}
return (`<script src="${script}"></script>`);
})
.join("\n"),
})
],
devServer: {
port: 8081,
inline: true,
compress: true,
proxy: [
{ path: '/polyfill.min.js', target: 'http://localhost:8081/node_modules/babel-polyfill/dist', bypass: log },
{ path: '/api/*', target: dhisConfig.baseUrl, bypass: log },
{ path: '/dhis-web-commons/**', target: dhisConfig.baseUrl, bypass: log },
{ path: '/icons/*', target: dhisConfig.baseUrl, bypass: log },
],
},
};
if (!isDevBuild) {
webpackConfig.plugins.push(
// Replace any occurance of process.env.NODE_ENV with the string 'production'
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
DHIS_CONFIG: JSON.stringify({}),
})
);
webpackConfig.plugins.push(
new webpack.optimize.OccurrenceOrderPlugin()
);
} else {
webpackConfig.plugins.push(
new webpack.DefinePlugin({
DHIS_CONFIG: JSON.stringify(dhisConfig)
})
);
}
module.exports = webpackConfig;