-
Notifications
You must be signed in to change notification settings - Fork 68
/
webpack.config.js
120 lines (117 loc) · 2.97 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
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerWebpackPlugin = require('css-minimizer-webpack-plugin');
const webpack = require('webpack');
const ReactRefreshPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const isEnvDevelopment = process.env.NODE_ENV !== 'production';
const isEnvProduction = process.env.NODE_ENV === 'production';
const shouldUseSourceMap = isEnvDevelopment;
module.exports = {
output: {
clean: true,
path: path.resolve('./dist/assets'),
filename: '[name].js',
libraryTarget: 'umd',
chunkFilename: '[name].[contenthash].js',
crossOriginLoading: 'anonymous',
pathinfo: true,
publicPath: '/assets/',
},
module: {
rules: [
// Handle node_modules packages that contain sourcemaps
shouldUseSourceMap && {
enforce: 'pre',
exclude: /@babel(?:\/|\\{1,2})runtime/,
test: /\.(js|mjs|jsx|ts|tsx|css)$/,
loader: require.resolve('source-map-loader'),
},
{
oneOf: [
{
test: /\.(t|j)sx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.(png|jpg|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
{
test: /\.(p|post)?css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
],
},
].filter(Boolean),
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
},
plugins: [
new ForkTsCheckerWebpackPlugin({
typescript: {
configOverwrite: {
compilerOptions: {
lib: ['ES2020', 'DOM', 'DOM.Iterable'],
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,
skipLibCheck: true,
inlineSourceMap: false,
declarationMap: false,
noEmit: true,
incremental: true,
jsx: 'preserve',
},
include: ['client/**/*'],
},
},
}),
new MiniCssExtractPlugin({
filename: '[name].css?v=[contenthash]',
}),
new ESLintPlugin({
context: path.resolve(__dirname, 'client'),
cache: true,
extensions: ['js', 'jsx', 'ts', 'tsx'],
}),
isEnvDevelopment && new webpack.HotModuleReplacementPlugin(),
isEnvDevelopment &&
new ReactRefreshPlugin({
overlay: {
sockIntegration: 'whm',
},
}),
].filter(Boolean),
mode: isEnvProduction ? 'production' : 'development',
entry: {
'management-ui-standalone': [
isEnvDevelopment && '@gatsbyjs/webpack-hot-middleware/client',
'./client/entry-standalone.tsx',
].filter(Boolean),
},
devtool: shouldUseSourceMap ? 'cheap-module-source-map' : false,
ignoreWarnings: [/Failed to parse source map/],
optimization: {
minimize: isEnvProduction,
minimizer: [
'...',
new CssMinimizerWebpackPlugin({
minimizerOptions: {
preset: [
'default',
{
discardComments: { removeAll: true },
},
],
},
}),
],
},
};