-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
133 lines (126 loc) · 3.78 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
"use strict";
var webpack = require("webpack");
var path = require("path");
var colors = require("colors");
const isDevBuild = process.argv[1].indexOf("webpack-dev-server") !== -1;
const dhisConfigPath = process.env.DHIS2_HOME
? `${process.env.DHIS2_HOME}/config`
: `${__dirname}/config`;
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:8031",
authorization: "Basic YWRtaW46ZGlzdHJpY3Q=", // admin:district
};
}
console.log(JSON.stringify(dhisConfig, null, 2), "\n");
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,
contentBase: __dirname,
entry: "./src/app.js",
devtool: "source-map",
output: {
path: __dirname + "/build",
filename: "app.js",
publicPath: "http://localhost:8081/",
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: "babel",
query: {
presets: ["es2015", "stage-0", "react"],
},
},
{
test: /\.css$/,
loader: "style!css",
},
{
test: /\.scss$/,
loader: "style!css!sass",
},
{
test: /\.json$/,
loader: "json-loader",
},
],
},
resolve: {
extensions: ["", ".js", ".jsx"],
alias: {
react: path.resolve("./node_modules/react"),
"material-ui": path.resolve("./node_modules/material-ui"),
d2: __dirname + "/node_modules/d2",
},
},
devServer: {
progress: true,
colors: true,
port: 8081,
inline: true,
compress: true,
proxy: [
{ path: "/api/*", target: dhisConfig.baseUrl, bypass: log },
{ path: "/dhis-web-commons/*", target: dhisConfig.baseUrl, bypass: log },
{ path: "/icons/*", target: dhisConfig.baseUrl, bypass: log },
{ path: "/css/*", target: "http://localhost:8081/build", bypass: log },
{ path: "/i18n/*", target: "http://localhost:8081/src", bypass: log },
{
path: "/jquery.min.js",
target: "http://localhost:8081/node_modules/jquery/dist",
bypass: log,
},
{
path: "/polyfill.min.js",
target: "http://localhost:8081/node_modules/babel-polyfill/dist",
bypass: log,
},
],
},
};
if (!isDevBuild) {
webpackConfig.plugins = [
// Replace any occurance of process.env.NODE_ENV with the string 'production'
new webpack.DefinePlugin({
"process.env.NODE_ENV": '"production"',
DHIS_CONFIG: JSON.stringify({}),
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
/*
new webpack.optimize.UglifyJsPlugin({
// compress: {
// warnings: false,
// },
comments: false,
beautify: true,
}),
*/
];
} else {
webpackConfig.plugins = [
new webpack.DefinePlugin({
DHIS_CONFIG: JSON.stringify(dhisConfig),
}),
];
}
module.exports = webpackConfig;