-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
202 lines (191 loc) · 4.52 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
const path = require("path")
const webpack = require("webpack")
const version = require("./version")
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const HtmlWebpackPlugin = require("html-webpack-plugin")
const ScriptPlugin = require("script-ext-html-webpack-plugin")
const UglifyJsPlugin = require("uglifyjs-webpack-plugin")
const TerserJSPlugin = require("terser-webpack-plugin")
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin")
const dev = "sample-api-react.herokuapp.com"
const prod = "dev.global.com"
var https = (target) => `https://${target}`
var http = (target) => `http://${target}`
var wss = (target) => `wss://${target}`
var ws = (target) => `ws://${target}`
const BUILD = process.env.BUILD || "build"
const CONFIG = process.env.CONFIG
const isDev = CONFIG == "dev"
console.log("\n\n")
console.log(`\x1b[32m\x1b[1m You are ${
isDev ? "running app devserver." : `building app.`
}\x1b[0m`)
if (!isDev) {
switch(BUILD) {
case "build":
console.log(`\x1b[32m\x1b[1m Increasing build... \x1b[0m`)
version.inc()
break
case "minor":
console.log(`\x1b[32m\x1b[1m Increasing MINOR version... \x1b[0m`)
version.incMinor()
break
case "major":
console.log(`\x1b[32m\x1b[1m Increasing MAJOR version, congrats! :) \x1b[0m`)
version.incMajor()
break
}
console.log(`\x1b[32m\x1b[1m Version has successfully increased. The PWA version is now ${version.v()} \x1b[0m`)
}
console.log("\n\n")
const PUBLIC_PATH = `/assets/${version.v()}/`
var config = {
mode: isDev ? "development" : "production",
entry: {
app: path.resolve(__dirname, "src/index.tsx")
},
output: isDev
? {
path: __dirname,
filename: "dist/bundle.js",
publicPath: "/"
}
: {
path: path.resolve(__dirname, `dist/${version.v()}`),
filename: `bundle.js`,
publicPath: PUBLIC_PATH,
},
...(isDev ?
{
devtool: "eval-source-map",
devServer: {
historyApiFallback: true,
hot: true,
disableHostCheck: true,
proxy: {
"/api/**": {
target: http(dev),
secure: false,
changeOrigin: true
},
}
},
} : {}),
module: {
rules: [
{
test: /\.(t|j)sx?$/,
loader: "awesome-typescript-loader",
options: {
useCache: false,
usePrecompiledFiles: false
},
exclude: /node_modules\/(?!superagent)/,
},
{
enforce: "pre",
test: /\.js$/,
loader: "source-map-loader"
},
{
test: /\.(svg|woff|woff2|ttf|otf|png|jpg)$/,
include: [
path.resolve(__dirname, "node_modules"),
path.resolve(__dirname, "src"),
],
loader: "url-loader",
query: {
limit: 1000,
name: `${version.v()}.[name].[ext]`
}
},
{
test: /\.html$/,
loader: "html-loader"
},
{
test: /\.worker\.js$/,
use: {
loader: "worker-loader",
options: {
name: `[name].js`,
}
}
},
{
test: /\.(sa|c)ss$/,
use: [
isDev ? "style-loader" : MiniCssExtractPlugin.loader,
"css-loader",
{
loader: "sass-loader",
options: {
sassOptions: {
includePaths: [
path.resolve(__dirname, "src")
]
}
}
}
]
},
]
},
resolve: {
modules: [
"node_modules",
path.resolve(__dirname, "src"),
],
extensions: [".js", ".jsx", ".sass", ".json", ".css", ".ts", ".tsx"]
},
performance: {
hints: "warning",
maxAssetSize: 20000000000,
maxEntrypointSize: 40000000000
},
parallelism: 2,
optimization: {
minimizer: [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin({})],
},
plugins: [
// new BundleAnalyzer(),
new webpack.DefinePlugin({
"ENV": JSON.stringify(CONFIG),
"process.env.HOST": "window.location.origin",
"process.env.VERSION": JSON.stringify(version.v()),
"process.env.NODE_ENV": JSON.stringify(isDev ? "development" : "production")
}),
...(!isDev ? [
new UglifyJsPlugin({
exclude: [/\.(min|worker)\.js$/gi],
uglifyOptions: {
ie8: false,
mangle: true,
output: {
comments: false,
beautify: false
}
}
}),
new HtmlWebpackPlugin({
template: "index.ejs",
filename: "index.html",
_preload: "",
_version: `<script>window.__APP_VERSION__ = "${version.v()}"</script>`,
_title: "${__rh-title}",
_meta: "${__rh-meta}",
_link: "${__rh-link}",
_htmlAttributes: "${__rh-htmlAttributes}",
_bodyAttributes: "${__rh-bodyAttributes}",
_body: "${__body}"
}),
new MiniCssExtractPlugin({
filename: `style.css`
}),
new ScriptPlugin({
defaultAttribute: "async"
}),
] : []),
],
}
module.exports = config