-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
90 lines (87 loc) · 2.58 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const bodyParser = require('body-parser');
module.exports = {
entry: './src/main.tsx',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/',
},
devtool: 'source-map',
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './index.html',
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
}),
process.env.ANALYZE && new BundleAnalyzerPlugin(),
].filter(Boolean),
devServer: {
port: 3000,
historyApiFallback: true,
hot: true,
open: true,
setupMiddlewares: (middlewares, devServer) => {
if (!devServer) {
throw new Error('webpack-dev-server is not defined');
}
devServer.app.use(bodyParser.json());
return middlewares;
},
proxy: {
'/api': {
target: 'https://b4mad.racing',
changeOrigin: true,
secure: false,
logLevel: 'debug',
onProxyReq: (proxyReq, req) => {
console.log(`[API Proxy] ${req.method} ${req.url}`);
},
onProxyRes: (proxyRes, req) => {
console.log(`[API Proxy] ${proxyRes.statusCode} ${req.method} ${req.url}`);
},
},
'/graphql': {
target: 'http://telemetry.b4mad.racing:30050',
changeOrigin: true,
secure: false,
logLevel: 'debug',
onProxyReq: (proxyReq, req) => {
console.log(`[GraphQL Proxy] ${req.method} ${req.url}`);
if (req.method === 'POST' && req.body) {
console.log('[GraphQL Query]', req.body.query);
console.log('[GraphQL Variables]', req.body.variables);
// Restream body data
const bodyData = JSON.stringify(req.body);
proxyReq.setHeader('Content-Type', 'application/json');
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
proxyReq.write(bodyData);
}
},
onProxyRes: (proxyRes, req) => {
console.log(`[GraphQL Proxy] ${proxyRes.statusCode} ${req.method} ${req.url}`);
},
},
},
},
};