This repository has been archived by the owner on Jan 5, 2021. It is now read-only.
forked from smart-on-fhir/patient-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
208 lines (185 loc) · 5.82 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
"use strict";
const Path = require("path");
const Webpack = require("webpack");
const Package = require("./package.json");
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ENV = process.env.NODE_ENV || "production";
const SRC = Path.join(__dirname, "src");
const DST = Path.join(__dirname, "build");
const PORT = process.env.PORT || 9001;
const HOST = process.env.HOST || "0.0.0.0";
let config = {
context: SRC,
entry: {
index : [
Path.join(SRC, "index.js")
],
"vendor": [
"react",
"react-dom",
"jquery",
"redux",
"redux-actions",
"react-redux",
"redux-thunk",
"react-router",
"react-router-dom",
"history",
"moment"
]
},
output: {
filename : "[name].js",
path : `${DST}/js/`,
publicPath: "/js/",
sourceMapFilename: "[file].[hash].map"
},
module: {
rules: [
{
test : /\.less$/,
include: [ SRC ],
use: [
"style-loader?singleton",
"css-loader",
"postcss-loader",
"less-loader"
]
}
]
},
// When importing a module whose path matches one of the following, just
// assume a corresponding global variable exists and use that instead.
// This is important because it allows us to avoid bundling all of our
// dependencies, which allows browsers to cache those libraries between builds.
// externals: {
// "react" : "React",
// "react-dom": "ReactDOM"
// },
resolve : {
extensions : [ ".js", ".jsx", ".less" ]
},
devtool: "#source-map",
stats: {
colors : true,
modules : true,
reasons : true,
errorDetails: true
},
plugins : [
new Webpack.DefinePlugin({
"process.env.NODE_ENV": "'" + ENV + "'",
"__APP_VERSION__" : "'" + Package.version + "'"
}),
new Webpack.optimize.CommonsChunkPlugin({
name : "vendor",
filename : "commons.js",
minChunks: 2
}),
new HtmlWebpackPlugin({
filename: DST + "/index.html",
template: SRC + "/index.ejs",
inject : false,
Webpack
})
]
}
if (ENV == "development") {
config.devServer = {
contentBase : DST,
historyApiFallback: true,
hot : true,
// inline : true,
quiet : false,
noInfo : false,
clientLogLevel : "warning",
publicPath: `http://${HOST}:${PORT}/js/`,
// publicPath: "/js/",
// Display only errors to reduce the amount of output.
stats: {
// Add asset Information
assets: true,
// Sort assets by a field
assetsSort: "field",
// Add information about cached (not built) modules
cached: true,
// Add children information
children: true,
// Add chunk information (setting this to `false` allows for a less verbose output)
chunks: true,
// Add built modules information to chunk information
chunkModules: false,
// Add the origins of chunks and chunk merging info
chunkOrigins: false,
// Sort the chunks by a field
chunksSort: "field",
// Context directory for request shortening
context: ".",
// `webpack --colors` equivalent
colors: true,
// Add errors
errors: true,
// Add details to errors (like resolving log)
errorDetails: true,
// Add the hash of the compilation
hash: true,
// Add built modules information
modules: false,
// Sort the modules by a field
modulesSort: "field",
// Add public path information
publicPath: true,
// Add information about the reasons why modules are included
reasons: true,
// Add the source code of modules
source: true,
// Add timing information
timings: true,
// Add webpack version information
version: true,
// Add warnings
warnings: true
},
watchOptions: {
ignored: /node_modules/
},
host: HOST,
port: PORT
};
config.module.rules.push({
test : /\.jsx?$/,
include: [ SRC ],
// exclude: [/node_modules/],
use : [ "react-hot-loader", "babel-loader" ]
});
config.plugins.push(
new Webpack.HotModuleReplacementPlugin(),
// prints more readable module names in the browser console
// on HMR updates
new Webpack.NamedModulesPlugin()
);
config.entry.index = [
"webpack-dev-server/client?http://localhost:" + PORT,
"webpack/hot/only-dev-server", // "only" prevents reload on syntax errors
"./index.js"
];
config.output.publicPath = "http://localhost:" + PORT + "/js/";
}
else if (ENV == "production") {
config.plugins.push(
new Webpack.optimize.UglifyJsPlugin({
sourceMap: true
}),
new BundleAnalyzerPlugin({
analyzerMode: "static",
openAnalyzer: false
})
);
config.module.rules.push({
test : /\.jsx?$/,
include: [ SRC ],
use : [ "babel-loader" ]
});
}
module.exports = config;