forked from chicagopcdc/data-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
166 lines (159 loc) · 4.55 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
const webpack = require('webpack');
const CompressionPlugin = require('compression-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const portalVersion = require('./package.json').version;
const basename = process.env.BASENAME || '/';
const pathPrefix = basename.endsWith('/')
? basename.slice(0, basename.length - 1)
: basename;
const isProduction = process.env.NODE_ENV === 'production';
const plugins = [
new CompressionPlugin(),
new webpack.EnvironmentPlugin({
MOCK_STORE: null,
BASENAME: '/',
PORTAL_VERSION: portalVersion || '',
}),
new webpack.DefinePlugin({
'process.env': {
LOGOUT_INACTIVE_USERS: !(process.env.LOGOUT_INACTIVE_USERS === 'false'),
WORKSPACE_TIMEOUT_IN_MINUTES:
process.env.WORKSPACE_TIMEOUT_IN_MINUTES || 480,
REACT_APP_PROJECT_ID: JSON.stringify(
process.env.REACT_APP_PROJECT_ID || 'search'
),
REACT_APP_DISABLE_SOCKET: JSON.stringify(
process.env.REACT_APP_DISABLE_SOCKET || 'true'
),
},
// disable React DevTools in production; see https://github.com/facebook/react/pull/11448
...(isProduction
? { __REACT_DEVTOOLS_GLOBAL_HOOK__: '({ isDisabled: true })' }
: {}),
}),
new HtmlWebpackPlugin({
title: process.env.TITLE || 'PCDC Data Portal',
basename: pathPrefix,
template: 'src/index.ejs',
connect_src: (() => {
const rv = {};
if (typeof process.env.FENCE_URL !== 'undefined') {
rv[new URL(process.env.FENCE_URL).origin] = true;
}
if (typeof process.env.INDEXD_URL !== 'undefined') {
rv[new URL(process.env.INDEXD_URL).origin] = true;
}
if (typeof process.env.WORKSPACE_URL !== 'undefined') {
rv[new URL(process.env.WORKSPACE_URL).origin] = true;
}
if (typeof process.env.WTS_URL !== 'undefined') {
rv[new URL(process.env.WTS_URL).origin] = true;
}
if (typeof process.env.MANIFEST_SERVICE_URL !== 'undefined') {
rv[new URL(process.env.MANIFEST_SERVICE_URL).origin] = true;
}
return Object.keys(rv).join(' ');
})(),
hash: true,
}),
new webpack.optimize.AggressiveMergingPlugin(), // Merge chunks
];
let optimization = {};
let devtool = false;
if (isProduction) {
// optimization for production mode
optimization = {
splitChunks: {
chunks: 'all',
},
};
} else {
// add sourcemap tools for development mode
devtool = 'eval-source-map';
// add react-refresh to plugins for development mode
plugins.push(
// eslint-disable-next-line global-require
new (require('@pmmmwh/react-refresh-webpack-plugin'))({ overlay: false })
);
}
module.exports = {
entry: './src/index.jsx',
target: 'web',
bail: isProduction,
mode: isProduction ? 'production' : 'development',
output: {
path: __dirname,
filename: isProduction
? '[name].[contenthash].bundle.js'
: '[name].bundle.js',
publicPath: isProduction ? basename : 'https://localhost:9443/',
},
optimization,
devtool,
devServer: {
historyApiFallback: {
index: 'dev.html',
},
allowedHosts: 'all',
hot: true,
port: 9443,
https: true,
headers: {
'Access-Control-Allow-Origin': '*',
},
},
module: {
rules: [
{
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
},
{
test: /\.jsx?$/,
exclude:
/node_modules\/(?!(graphiql|graphql-language-service-parser)\/).*/,
loader: 'babel-loader',
options: isProduction
? undefined
: { plugins: [require.resolve('react-refresh/babel')] },
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader'],
},
{
test: /\.svg$/,
use: ['@svgr/webpack'],
},
{
test: /\.(png|jpg|gif)$/,
type: 'asset/inline',
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
],
},
resolve: {
alias: {
"@adobe/react-spectrum": path.resolve('./node_modules/@adobe/react-spectrum/dist/main.js'),
graphql: path.resolve('./node_modules/graphql'),
react: path.resolve('./node_modules/react'), // Same issue.
graphiql: path.resolve('./node_modules/graphiql'),
'graphql-language-service-parser': path.resolve(
'./node_modules/graphql-language-service-parser'
),
},
extensions: ['.mjs', '.js', '.jsx', '.json'],
},
plugins,
externals: [
{
xmlhttprequest: '{XMLHttpRequest:XMLHttpRequest}',
},
],
};