forked from SigNoz/signoz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.prod.js
214 lines (207 loc) · 5.46 KB
/
webpack.config.prod.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// shared config (dev and prod)
const { resolve } = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const { sentryWebpackPlugin } = require('@sentry/webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const dotenv = require('dotenv');
const webpack = require('webpack');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const Critters = require('critters-webpack-plugin');
const { RetryChunkLoadPlugin } = require('webpack-retry-chunk-load-plugin');
dotenv.config();
const cssLoader = 'css-loader';
const sassLoader = 'sass-loader';
const styleLoader = 'style-loader';
const plugins = [
new HtmlWebpackPlugin({
template: 'src/index.html.ejs',
INTERCOM_APP_ID: process.env.INTERCOM_APP_ID,
SEGMENT_ID: process.env.SEGMENT_ID,
CLARITY_PROJECT_ID: process.env.CLARITY_PROJECT_ID,
SENTRY_AUTH_TOKEN: process.env.SENTRY_AUTH_TOKEN,
SENTRY_ORG: process.env.SENTRY_ORG,
SENTRY_PROJECT_ID: process.env.SENTRY_PROJECT_ID,
SENTRY_DSN: process.env.SENTRY_DSN,
TUNNEL_URL: process.env.TUNNEL_URL,
TUNNEL_DOMAIN: process.env.TUNNEL_DOMAIN,
}),
new CompressionPlugin({
exclude: /.map$/,
}),
new CopyPlugin({
patterns: [{ from: resolve(__dirname, 'public/'), to: '.' }],
}),
new webpack.ProvidePlugin({
process: 'process/browser',
}),
new webpack.DefinePlugin({
'process.env': JSON.stringify({
FRONTEND_API_ENDPOINT: process.env.FRONTEND_API_ENDPOINT,
INTERCOM_APP_ID: process.env.INTERCOM_APP_ID,
SEGMENT_ID: process.env.SEGMENT_ID,
CLARITY_PROJECT_ID: process.env.CLARITY_PROJECT_ID,
SENTRY_AUTH_TOKEN: process.env.SENTRY_AUTH_TOKEN,
SENTRY_ORG: process.env.SENTRY_ORG,
SENTRY_PROJECT_ID: process.env.SENTRY_PROJECT_ID,
SENTRY_DSN: process.env.SENTRY_DSN,
TUNNEL_URL: process.env.TUNNEL_URL,
TUNNEL_DOMAIN: process.env.TUNNEL_DOMAIN,
}),
}),
new MiniCssExtractPlugin(),
new Critters({
preload: 'swap',
// Base path location of the CSS files
path: resolve(__dirname, './build/css'),
// Public path of the CSS resources. This prefix is removed from the href
publicPath: resolve(__dirname, './public/css'),
fonts: true,
}),
sentryWebpackPlugin({
authToken: process.env.SENTRY_AUTH_TOKEN,
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT_ID,
}),
new RetryChunkLoadPlugin({
maxRetries: 2,
}),
];
if (process.env.BUNDLE_ANALYSER === 'true') {
plugins.push(new BundleAnalyzerPlugin({ analyzerMode: 'server' }));
}
const config = {
mode: 'production',
devtool: 'source-map',
entry: resolve(__dirname, './src/index.tsx'),
output: {
path: resolve(__dirname, './build'),
publicPath: '/',
filename: '[name].[contenthash].js',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
plugins: [new TsconfigPathsPlugin({})],
fallback: { 'process/browser': require.resolve('process/browser') },
},
cache: {
type: 'filesystem',
allowCollectingMemory: true,
cacheDirectory: resolve(__dirname, '.temp_cache'),
buildDependencies: {
// This makes all dependencies of this file - build dependencies
config: [__filename],
// By default webpack and loaders are build dependencies
},
},
module: {
rules: [
{
test: [/\.jsx?$/, /\.tsx?$/],
use: ['babel-loader'],
exclude: /node_modules/,
},
{
test: /\.md$/,
use: 'raw-loader',
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: cssLoader,
options: {
modules: true,
},
},
],
},
{
test: /\.s[ac]ss$/i,
use: [
// Creates `style` nodes from JS strings
styleLoader,
// Translates CSS into CommonJS
cssLoader,
// Compiles Sass to CSS
sassLoader,
],
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
use: [
'file-loader?hash=sha512&digest=hex&name=img/[chunkhash].[ext]',
'image-webpack-loader?bypassOnDebug&optipng.optimizationLevel=7&gifsicle.interlaced=false',
],
},
{
test: /\.(ttf|eot|woff|woff2)$/,
use: ['file-loader'],
},
{
test: /\.less$/i,
use: [
{
loader: styleLoader,
},
{
loader: cssLoader,
options: {
modules: true,
},
},
{
loader: 'less-loader',
options: {
lessOptions: {
javascriptEnabled: true,
},
},
},
],
},
],
},
plugins,
optimization: {
chunkIds: 'named',
concatenateModules: false,
emitOnErrors: true,
flagIncludedChunks: true,
innerGraph: true, // tells webpack whether to conduct inner graph analysis for unused exports.
mangleWasmImports: true,
mergeDuplicateChunks: true,
minimize: true,
nodeEnv: 'production',
runtimeChunk: {
name: (entrypoint) => `runtime~${entrypoint.name}`,
},
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
compress: true,
keep_classnames: true,
keep_fnames: false,
sourceMap: false,
safari10: true,
parse: {
html5_comments: false,
},
},
}),
new CssMinimizerPlugin(),
],
},
performance: {
hints: 'warning',
},
};
module.exports = config;