-
Notifications
You must be signed in to change notification settings - Fork 145
/
webpack.config.js
88 lines (84 loc) · 2.44 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
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const { sentryWebpackPlugin } = require('@sentry/webpack-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const circularPlugin = new CircularDependencyPlugin({
// exclude detection of files based on a RegExp
exclude: /a\.js|node_modules/,
// add errors to webpack instead of warnings
failOnError: false,
// allow import cycles that include an asyncronous import,
// e.g. via import(/* webpackMode: "weak" */ './file.js')
allowAsyncCycles: false,
// set the current working directory for displaying module paths
cwd: process.cwd(),
});
const circularValidation = false;
const rules = [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
options: {
presets: ['@babel/env'],
//plugins: [isDevelopment && require.resolve('react-refresh/babel')].filter(Boolean),
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.pcss$/,
use: ['style-loader', 'css-loader', 'postcss-loader'],
},
{
test: /\.js$/,
exclude: /(node_modules\/react-leaflet-heatmap-layer-v3)/,
enforce: 'pre',
use: ['source-map-loader'],
},
{
test: /.(png|svg|jpe?g|gif|woff2?|ttf|eot)$/,
use: ['file-loader'],
},
];
// TODO - move this config to a dedicated environment file.
// TODO - use process.env.NODE_ENV which will directly return the environment string "development", "production".
module.exports = (env) => {
const production = env.production;
return {
experiments: {
topLevelAwait: true,
},
entry: ['./src/index.tsx'],
mode: production ? 'production' : 'development',
devtool: production ? 'source-map' : 'eval-cheap-module-source-map',
module: {
rules: rules,
},
resolve: { extensions: ['*', '.js', '.jsx', '.ts', '.tsx'] },
output: {
filename: 'bundle.js',
},
devServer: {
port: 3000,
hot: true,
compress: true,
client: {
overlay: {
warnings: false,
},
},
},
plugins: production
? [
sentryWebpackPlugin({
authToken: process.env.SENTRY_AUTH_TOKEN,
org: 'neo4j-inc',
project: 'neodash',
}),
]
: [new ReactRefreshWebpackPlugin(), ...(circularValidation ? [circularPlugin] : [])],
ignoreWarnings: [/Failed to parse source map/],
};
};