-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.prod.js
200 lines (182 loc) · 7.3 KB
/
webpack.config.prod.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
/*
University of Illinois/NCSA Open Source License
Copyright (c) 2018 Terrain Data, Inc. and the authors. All rights reserved.
Developed by: Terrain Data, Inc. and
the individuals who committed the code in this file.
https://github.com/terraindata/terrain
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal with the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimers.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimers in the
documentation and/or other materials provided with the distribution.
* Neither the names of Terrain Data, Inc., Terrain, nor the names of its
contributors may be used to endorse or promote products derived from
this Software without specific prior written permission.
This license supersedes any copyright notice, license, or related statement
following this comment block. All files in this repository are provided
under the same license, regardless of whether a corresponding comment block
appears in them. This license also applies retroactively to any previous
state of the repository, including different branches and commits, which
were made public on or after December 8th, 2018.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
THE SOFTWARE.
*/
const webpack = require('webpack');
const path = require('path');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const CompressionPlugin = require("compression-webpack-plugin");
module.exports =
{
entry: './src/app/Root.tsx',
output:
{
path: __dirname,
publicPath: '/midway/v1/bundles/', // this is where midway stores bundles
filename: 'bundle.js',
chunkFilename: '[name].bundle.js'
},
// NOTE: this should also be added to the production config
devServer: {
headers: {
'Access-Control-Allow-Origin': '*'
},
// proxy midway requests to dev midway
proxy: {
'/midway/**': {
target: 'http://localhost:3000/midway',
pathRewrite: { '^/midway': '' },
secure: false,
proxyTimeout: 60*60*1000,
timeout: 60*60*1000
// logLevel: 'debug', // useful when debugging
},
},
},
resolve:
{
// it is important that .tsx is before .less, so that it resolves first, so that files that share a name resolve correctly
extensions: [ '.js', '.tsx', '.jsx', '.ts', '.css', '.less', '.json', '.svg' ],
alias: {
auth: path.resolve(__dirname, 'src/app/auth'),
analytics: path.resolve(__dirname, 'src/app/analytics'),
app: path.resolve(__dirname, 'src/app'),
builder: path.resolve(__dirname, 'src/app/builder'),
charts: path.resolve(__dirname, 'src/app/charts'),
colors: path.resolve(__dirname, 'src/app/colors'),
common: path.resolve(__dirname, 'src/app/common'),
control: path.resolve(__dirname, 'src/app/control'),
database: path.resolve(__dirname, 'src/database'),
deploy: path.resolve(__dirname, 'src/app/deploy'),
etl: path.resolve(__dirname, 'src/app/etl'),
images: path.resolve(__dirname, 'src/images'),
jobs: path.resolve(__dirname, 'src/app/jobs'),
library: path.resolve(__dirname, 'src/app/library'),
manual: path.resolve(__dirname, 'src/app/manual'),
roles: path.resolve(__dirname, 'src/app/roles'),
scheduler: path.resolve(__dirname, 'src/app/scheduler'),
schema: path.resolve(__dirname, 'src/app/schema'),
shared: path.resolve(__dirname, 'shared'),
src: path.resolve(__dirname, 'src'),
store: path.resolve(__dirname, 'src/app/store'),
tql: path.resolve(__dirname, 'src/app/tql'),
users: path.resolve(__dirname, 'src/app/users'),
util: path.resolve(__dirname, 'src/app/util'),
x: path.resolve(__dirname, 'src/app/x'),
'test-helpers': path.resolve(__dirname, 'src/test/test-helpers'),
radium: require.resolve('radium/index'),
},
},
module:
{
rules:
[
// note: this first loader string gets updated in webpack.config.prod.js
// keep it first in this list
{
test: /\.ts(x?)$/,
exclude: [/midway/, /analytics.js/, /sigint/, /node_modules/],
loader:
'babel-loader!thread-loader!ts-loader?happyPackMode=true'
+ JSON.stringify({
compilerOptions: {
},
}),
},
{
test: /\.js(x?)$/,
exclude: [/midway/, /analytics.js/, /node_modules/],
loader: 'babel-loader!thread-loader'
},
{ test: /\.css$/, exclude: /midway/, loader: 'style-loader!css-loader' },
{ test: /\.less$/, exclude: /midway/, loader: 'style-loader!css-loader!less-loader?strictMath&noIeCompat' }, /* Note: strictMath enabled; noIeCompat also */
{ test: /\.woff(2?)$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff' },
{ test: /\.ttf$/, loader: 'file-loader' },
{ test: /\.eot$/, loader: 'file-loader' },
{ test: /\.jpg$/, loader: 'file-loader' },
{ test: /\.gif$/, loader: 'url-loader?limit=4000000' },
{ test: /\.png$/, loader: 'url-loader?limit=4000000' },
{ test: require.resolve('jquery'), use: [{ loader: 'expose-loader', options: '$' }]},
{
test: /\.svg(\?name=[a-zA-Z]*)*$/,
exclude: [/midway/, /node_modules/],
loader: 'svg-react-loader',
},
{ test: /\.txt$/, exclude: /midway/, loader: 'raw-loader' },
],
},
plugins:
[
new webpack.DefinePlugin({
DEV: false,
}),
new HardSourceWebpackPlugin({
cacheDirectory: './.cache/hard-source/dev/[confighash]',
}),
new ForkTsCheckerWebpackPlugin({ tslint: true, checkSyntacticErrors: true, workers: 1 }),
// new BundleAnalyzerPlugin(),
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8
})
],
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
test: /node_modules/,
chunks: "initial",
name: "vendor",
enforce: true
}
}
},
minimizer: [
new UglifyJSPlugin({
// sourceMap: true,
cache: true,
parallel: true,
uglifyOptions: {
keep_fnames: true,
}
})
],
},
};