-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
104 lines (97 loc) · 2.91 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
"use strict";
const webpack = require("webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HTMLWebpackPlugin = require("html-webpack-plugin");
//const dhisConfigPath = process.env.DHIS2_HOME && `${process.env.DHIS2_HOME}/config`;
var dhisConfig;
try {
dhisConfig = require("./d2auth.json"); // eslint-disable-line
} 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 YWRtaW46ZGlzdHJpY3Q=", // admin:district
};
}
const devServerPort = 8081;
const isDevBuild = process.argv[1].indexOf("webpack-dev-server") !== -1;
const webpackConfig = {
context: __dirname,
entry: "./src/app.js",
devtool: "source-map",
output: {
path: __dirname + "/build",
filename: "[name]-[hash].js",
publicPath: isDevBuild ? "http://localhost:8081/" : "./"
},
module: {
rules: [
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
},
{
test: /\.scss$/,
use: ["style-loader", "css-loader", "sass-loader"]
},
{
test: /\.html$/,
use: ["html-loader"]
},
{
test: /\.png$/,
use: ["url-loader?limit=100000"]
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: ["url-loader?limit=10000&mimetype=application/font-woff"]
},
{
test: /\.(ttf|otf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?|(jpg|gif)$/,
use: ["file-loader"]
}
]
},
resolve: {
alias: {}
},
plugins: [
new HTMLWebpackPlugin({
template: "src/index.html"
}),
new CopyWebpackPlugin({
"patterns": [
{ from: "./src/css", to: "css" },
{ from: "./src/img", to: "img" }
]
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
}),
!isDevBuild ? undefined : new webpack.DefinePlugin({
DHIS_CONFIG: JSON.stringify(dhisConfig),
}),
isDevBuild ? undefined : new webpack.DefinePlugin({
"process.env.NODE_ENV": "\"production\"",
DHIS_CONFIG: JSON.stringify({}),
}),
].filter(v => v),
devServer: {
port: devServerPort,
compress: true,
proxy: [
{
context: ["/api"],
target: "http://localhost:8080/dhis",
auth: "system:System123",
secure: false,
changeOrigin: true
}
]
},
mode: "development"
};
module.exports = webpackConfig;