-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
webpack.config.js
106 lines (100 loc) · 2.6 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
//plugins
const { DefinePlugin } = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
//libraries
const path = require('path');
//the exported config function
module.exports = ({ production, development, local, analyze }) => {
return {
mode: production ? "production" : "development",
entry: path.resolve(__dirname, 'client', 'client.jsx'),
output: {
path: path.resolve(__dirname, 'public'),
publicPath: '/',
filename: '[name].[chunkhash].js',
sourceMapFilename: '[name].[chunkhash].js.map'
},
devtool: production ? false : 'eval-source-map',
resolve: {
extensions: ['.js', '.jsx']
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules)/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: ['@babel/plugin-syntax-dynamic-import']
}
}
]
},
{
test: /\.(css)$/,
use: ['style-loader', 'css-loader']
},
]
},
plugins: [
new DefinePlugin({
'process.env': {
'PRODUCTION': production,
'NEWS_URI': production ? `"${process.env.NEWS_URI}"` : development ? '"https://dev-news.krgamestudios.com"' : '"http://localhost:3100"',
'AUTH_URI': production ? `"${process.env.AUTH_URI}"` : development ? '"https://dev-auth.krgamestudios.com"' : '"http://localhost:3200"',
'CHAT_URI': production ? `"${process.env.CHAT_URI}"` : development ? '"https://dev-chat.krgamestudios.com"' : '"http://localhost:3300"',
}
}),
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['*', '!content*']
}),
new HtmlWebpackPlugin({
template: './client/template.html',
minify: {
collapseWhitespace: production,
removeComments: production,
removeAttributeQuotes: production
}
}),
new CompressionPlugin({
filename: "[path][base].gz[query]",
algorithm: "gzip",
test: /\.js$|\.css$/,
minRatio: 0.8
}),
new BundleAnalyzerPlugin({
analyzerMode: analyze ? 'server' : 'disabled'
})
],
devServer: {
hot: true,
host: 'localhost',
port: 3001,
client: {
overlay: {
errors: true,
warnings: true,
},
},
watchFiles: {
options: {
ignored: ['node_modules/**']
}
},
proxy: [
{
context: ['/api'],
target: 'http://localhost:3000',
}
],
static: '/public',
historyApiFallback: true
}
}
};