-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
189 lines (187 loc) · 5.46 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
const webpack = require("webpack");
const path = require("path");
const TerserWebpackPlugin = require("terser-webpack-plugin");
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const FileManagerPlugin = require("filemanager-webpack-plugin");
/* document title is being populated at runtime, this is just a placeholder */
const appTitle = "Patient Search";
const templateFilePath = path.join(__dirname, "/patientsearch/src/index.html");
module.exports = function(_env, argv) {
const isProduction = argv.mode === "production";
const isDevelopment = !isProduction;
/*
* output to static file for ease of development
*/
const outputDirectory = isDevelopment?"/patientsearch/static":"/patientsearch/dist";
const jsDirectory = `${outputDirectory}/js`;
const templateDirectory = `${outputDirectory}/templates`;
return {
entry: {
"index" : ["whatwg-fetch", path.join(__dirname, "/patientsearch/src/js/containers/Entry.js")],
"info": ["whatwg-fetch", path.join(__dirname, "/patientsearch/src/js/containers/Landing.js")],
"logout": ["whatwg-fetch", path.join(__dirname, "/patientsearch/src/js/containers/Logout.js")],
"targetLaunch": ["whatwg-fetch", path.join(__dirname, "/patientsearch/src/js/containers/TargetLaunch.js")]
},
watchOptions: {
aggregateTimeout: 300,
poll: 1000
},
output: {
path: path.join(__dirname, jsDirectory),
/*
* create a new hash for each new build
*/
filename: "app.bundle.[name]-[hash:6].js",
publicPath: "/static/js/"
},
resolve: {
extensions: [".js", ".jsx", ".css"]
},
module: {
rules: [
//parse css files
{
test: /\.css$/,
use:[ {
loader: "style-loader"
}, {
loader: "css-loader",
options: {
"sourceMap": !isProduction
}
}]
},
{
test: /\.(png|jpe?g|gif)$/i,
loader: "url-loader"
},
{
test: /\.js?/,
exclude: /node_modules/,
use: "babel-loader"
},
{
test: /\.json$/,
use: "json-loader",
type: "javascript/auto"
},
{
test: /\.s[ac]ss$/i,
use: [
// Creates `style` nodes from JS strings
"style-loader",
// Translates CSS into CommonJS
"css-loader",
// Compiles Sass to CSS
"sass-loader",
],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: appTitle,
template: templateFilePath,
filename: path.join(__dirname, `${templateDirectory}/index.html`),
chunks: ["index"]
}),
new HtmlWebpackPlugin({
title: appTitle,
template: templateFilePath,
filename: path.join(__dirname, `${templateDirectory}/home.html`),
chunks: ["info"]
}),
new HtmlWebpackPlugin({
title: appTitle,
template: templateFilePath,
filename: path.join(__dirname, `${templateDirectory}/logout.html`),
chunks: ["logout"]
}),
new HtmlWebpackPlugin({
title: appTitle,
template: templateFilePath,
filename: path.join(__dirname, `${templateDirectory}/targetLaunch.html`),
chunks: ["targetLaunch"]
}),
new webpack.ProvidePlugin({
React: "react",
Promise: "es6-promise"
}),
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(
isProduction ? "production" : "development"
)
}),
new FileManagerPlugin({
onStart: {
delete: [
path.join(__dirname, "/patientsearch/dist")
]
},
onEnd: {
copy: [
{
source: path.join(__dirname, "/patientsearch/src/public"),
destination: path.join(__dirname, "/patientsearch/dist/public")
}
]
}
})
],
devServer: {
compress: true,
historyApiFallback: true,
open: true,
overlay: true,
contentBase: "./dist",
},
optimization: {
minimize: true,
minimizer: [
new TerserWebpackPlugin({
terserOptions: {
compress: {
comparisons: false
},
mangle: {
safari10: true
},
output: {
comments: false,
ascii_only: true
},
sourceMap: !isProduction,
warnings: false
}
}),
new OptimizeCssAssetsPlugin({
verbose: true
}),
],
splitChunks: {
chunks: "all",
minSize: 0,
maxInitialRequests: 20,
maxAsyncRequests: 20,
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
name(module, chunks, cacheGroupKey) {
const packageName = module.context.match(
/[\\/]node_modules[\\/](.*?)([\\/]|$)/
)[1];
return `${cacheGroupKey}.${packageName.replace("@", "")}`;
}
},
common: {
minChunks: 3,
priority: -10
}
}
}
}
};
};