-
Notifications
You must be signed in to change notification settings - Fork 848
Expand file tree
/
Copy pathwebpack.config.js
More file actions
473 lines (464 loc) · 14.9 KB
/
webpack.config.js
File metadata and controls
473 lines (464 loc) · 14.9 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2026, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
// Import file, libraries and plugins
const path = require('path');
const webpack = require('webpack');
const sourceDir = __dirname + '/pgadmin/static';
// webpack.shim.js contains path references for resolve > alias configuration
// and other util function used in CommonsChunksPlugin.
const webpackShimConfig = require('./webpack.shim');
const PRODUCTION = process.env.NODE_ENV === 'production';
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const extractStyle = new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[name].css',
});
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const CopyPlugin = require('copy-webpack-plugin');
const ImageMinimizerPlugin = require('image-minimizer-webpack-plugin');
let isSharpAvailable = true;
try {
const sharp = require('sharp');
// It is possible that sharp is installed but fails on running
sharp();
} catch {
isSharpAvailable = false;
console.warn('Sharp is not available, image optimization will be disabled.');
}
const envType = PRODUCTION ? 'production': 'development';
const devToolVal = PRODUCTION ? false : 'eval';
const analyzerMode = process.env.ANALYZE=='true' ? 'static' : 'disabled';
const outputPath = __dirname + '/pgadmin/static/js/generated';
// Expose libraries in app context so they need not to
// require('libname') when used in a module
const providePlugin = new webpack.ProvidePlugin({
_: 'lodash',
pgAdmin: 'sources/pgadmin',
'moment': 'moment',
'window.moment':'moment',
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
});
// Helps in debugging each single file, it extracts the module files
// from bundle so that they are accessible by search in Chrome's sources panel.
// Reference: https://webpack.js.org/plugins/source-map-dev-tool-plugin/#components/sidebar/sidebar.jsx
const sourceMapDevToolPlugin = new webpack.SourceMapDevToolPlugin({
filename: '[name].js.map',
exclude: /(vendor|codemirror|pgadmin\.js|pgadmin.theme|pgadmin.static|style\.js|popper)/,
columns: false,
});
// can be enabled using bundle:analyze
const bundleAnalyzer = new BundleAnalyzerPlugin({
analyzerMode: analyzerMode,
reportFilename: 'analyze_report.html',
});
const copyFiles = new CopyPlugin({
patterns: [
{
from: './pgadmin/static/img/*.png',
to: 'img/[name][ext]',
},
],
});
module.exports = [{
mode: envType,
devtool: devToolVal,
stats: { children: false, builtAt: true, chunks: true, timings: true },
// The base directory, an absolute path, for resolving entry points and loaders
// from configuration.
context: __dirname,
// Specify entry points of application
entry: {
'app.bundle': sourceDir + '/bundle/app.js',
'security.pages': 'security.pages',
sqleditor: './pgadmin/tools/sqleditor/static/js/index.js',
schema_diff: './pgadmin/tools/schema_diff/static/js/index.js',
erd_tool: './pgadmin/tools/erd/static/js/index.js',
psql_tool: './pgadmin/tools/psql/static/js/index.js',
debugger: './pgadmin/tools/debugger/static/js/index.js',
style: ['./pgadmin/static/css/style.css', './pgadmin/static/js/pgadmin.fonticon.js']
},
// path: The output directory for generated bundles(defined in entry)
// Ref: https://webpack.js.org/configuration/output/#output-library
output: {
libraryTarget: 'amd',
path: outputPath,
filename: '[name].js',
chunkFilename: '[name].chunk.js?id=[chunkhash]',
libraryExport: 'default',
publicPath: '',
},
// Templates files which contains python code needs to load dynamically
// Such files specified in externals are loaded at first and defined in
// the start of generated bundle within define(['libname'],fn) etc.
externals: webpackShimConfig.externals,
module: {
// References:
// Module and Rules: https://webpack.js.org/configuration/module/
// Loaders: https://webpack.js.org/loaders/
//
// imports-loader: it adds dependent modules(use:imports-loader?module1)
// at the beginning of module it is dependency.
// It solves number of problems
// Ref: http:/github.com/webpack-contrib/imports-loader/
rules: [{
test: /\.fonticon\.js/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false,
},
},
'webfonts-loader',
],
},{
test: /\.m?js$/,
resolve: {
fullySpecified: false
},
},{
test: /\.tsx?$|\.ts?$|\.jsx?$/,
exclude: [/node_modules/, /vendor/],
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', {'modules': 'commonjs', 'useBuiltIns': 'usage', 'corejs': 3}], ['@babel/preset-react', {
'runtime': 'automatic'
}], '@babel/preset-typescript'],
plugins: ['@babel/plugin-transform-class-properties', '@babel/plugin-transform-object-rest-spread'],
},
},
}, {
test: /external_table.*\.js/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', {'modules': 'commonjs', 'useBuiltIns': 'usage', 'corejs': 3}]],
},
},
}, {
// Transforms the code in a way that it works in the webpack environment.
// It uses imports-loader internally to load dependency. Its
// configuration is specified in webpack.shim.js
// Ref: https://www.npmjs.com/package/shim-loader
test: /\.js/,
exclude: [/external_table/],
loader: 'shim-loader',
options: webpackShimConfig,
include: path.join(__dirname, '/pgadmin/browser'),
}, {
// imports-loader: it adds dependent modules(use:imports-loader?module1)
// at the beginning of module it is dependency.
// It solves number of problems
// Ref: http:/github.com/webpack-contrib/imports-loader/
test: require.resolve('./pgadmin/tools/sqleditor/static/js/index'),
use: {
loader: 'imports-loader',
options: {
type: 'commonjs',
imports: [
'pure|pgadmin.tools.user_management',
'pure|pgadmin.browser.bgprocessmanager',
'pure|pgadmin.node.server_group',
'pure|pgadmin.node.server',
'pure|pgadmin.node.database',
'pure|pgadmin.node.role',
'pure|pgadmin.node.cast',
'pure|pgadmin.node.publication',
'pure|pgadmin.node.subscription',
'pure|pgadmin.node.tablespace',
'pure|pgadmin.node.directory',
'pure|pgadmin.node.resource_group',
'pure|pgadmin.node.event_trigger',
'pure|pgadmin.node.extension',
'pure|pgadmin.node.language',
'pure|pgadmin.node.foreign_data_wrapper',
'pure|pgadmin.node.foreign_server',
'pure|pgadmin.node.user_mapping',
'pure|pgadmin.node.schema',
'pure|pgadmin.node.catalog',
'pure|pgadmin.node.foreign_table_column',
'pure|pgadmin.node.catalog_object',
'pure|pgadmin.node.collation',
'pure|pgadmin.node.domain',
'pure|pgadmin.node.domain_constraints',
'pure|pgadmin.node.foreign_table',
'pure|pgadmin.node.fts_configuration',
'pure|pgadmin.node.fts_dictionary',
'pure|pgadmin.node.fts_parser',
'pure|pgadmin.node.fts_template',
'pure|pgadmin.node.function',
'pure|pgadmin.node.procedure',
'pure|pgadmin.node.edbfunc',
'pure|pgadmin.node.edbproc',
'pure|pgadmin.node.edbvar',
'pure|pgadmin.node.trigger_function',
'pure|pgadmin.node.package',
'pure|pgadmin.node.sequence',
'pure|pgadmin.node.synonym',
'pure|pgadmin.node.type',
'pure|pgadmin.node.rule',
'pure|pgadmin.node.index',
'pure|pgadmin.node.row_security_policy',
'pure|pgadmin.node.trigger',
'pure|pgadmin.node.catalog_object_column',
'pure|pgadmin.node.view',
'pure|pgadmin.node.mview',
'pure|pgadmin.node.table',
'pure|pgadmin.node.partition',
'pure|pgadmin.node.compound_trigger',
'pure|pgadmin.node.aggregate',
'pure|pgadmin.node.operator',
'pure|pgadmin.node.dbms_job_scheduler',
'pure|pgadmin.node.replica_node',
'pure|pgadmin.node.pgd_replication_groups',
'pure|pgadmin.node.pgd_replication_servers',
],
},
},
},{
test: require.resolve('./pgadmin/static/bundle/browser'),
use: {
loader: 'imports-loader',
options: {
type: 'commonjs',
imports: [
'pure|pgadmin.about',
'pure|pgadmin.preferences',
'pure|pgadmin.settings',
'pure|pgadmin.tools.backup',
'pure|pgadmin.tools.restore',
'pure|pgadmin.tools.grant_wizard',
'pure|pgadmin.tools.maintenance',
'pure|pgadmin.tools.import_export',
'pure|pgadmin.tools.import_export_servers',
'pure|pgadmin.tools.debugger',
'pure|pgadmin.node.pga_job',
'pure|pgadmin.tools.schema_diff',
'pure|pgadmin.tools.file_manager',
'pure|pgadmin.tools.search_objects',
'pure|pgadmin.tools.erd',
'pure|pgadmin.tools.psql',
'pure|pgadmin.tools.sqleditor',
'pure|pgadmin.misc.cloud',
'pure|pgadmin.browser.ai_tools',
],
},
},
},
{
test: /\.svg$/,
oneOf: [
{
issuer: /\.[jt]sx?$/,
resourceQuery: /svgr/,
use: ['@svgr/webpack'],
},
{
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 4 * 1024, // 4kb
}
}
},
],
},{
test: /\.(jpe?g|png|gif)$/i,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 4 * 1024, // 4kb
},
},
generator: {
filename: 'img/[name].[ext]',
},
exclude: /vendor/,
},{
test: /\.(eot|ttf|woff|woff2)$/,
type: 'asset/resource',
generator: {
filename: 'fonts/[name].[ext]',
},
include: [
/node_modules/,
path.join(sourceDir, '/css/'),
path.join(sourceDir, '/fonts/'),
],
exclude: /vendor/,
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '',
},
},
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: () =>({
plugins: [
require('autoprefixer')(),
],
}),
},
},
],
}],
// Prevent module from parsing through webpack, helps in reducing build time
noParse: [/moment.js/],
},
resolve: {
alias: webpackShimConfig.resolveAlias,
modules: ['node_modules', '.'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
unsafeCache: true,
fallback: {
'fs': false
},
},
// Watch mode Configuration: After initial build, webpack will watch for
// changes in files and compiles only files which are changed,
// if watch is set to True
// Reference: https://webpack.js.org/configuration/watch/#components/sidebar/sidebar.jsx
watchOptions: {
aggregateTimeout: 300,
poll: 1000,
ignored: /node_modules/,
},
optimization: {
minimizer: PRODUCTION ? [
new TerserPlugin({
parallel: false,
extractComments: true,
terserOptions: {
compress: true,
},
}),
].concat(isSharpAvailable ? [
new ImageMinimizerPlugin({
test: /\.(jpe?g|png|gif)$/i,
minimizer: {
implementation: ImageMinimizerPlugin.sharpMinify,
options: {
encodeOptions: {
jpeg: {
quality: 100,
},
webp: {
lossless: true,
},
avif: {
lossless: true,
},
png: {},
gif: {},
},
},
},
}),
] : []) : [],
splitChunks: {
cacheGroups: {
vendor_sqleditor: {
name: 'vendor_sqleditor',
filename: 'vendor.sqleditor.js',
chunks: 'all',
reuseExistingChunk: true,
priority: 9,
minChunks: 2,
enforce: true,
test(module) {
return webpackShimConfig.matchModules(module, ['jsoneditor', 'leaflet']);
},
},
vendor_react: {
name: 'vendor_react',
filename: 'vendor.react.js',
chunks: 'all',
reuseExistingChunk: true,
priority: 8,
minChunks: 2,
enforce: true,
test(module) {
return webpackShimConfig.matchModules(module, ['react', 'react-dom']);
},
},
vendor_main: {
name: 'vendor_main',
filename: 'vendor.main.js',
chunks: 'all',
reuseExistingChunk: true,
priority: 7,
minChunks: 2,
enforce: true,
test(module) {
return webpackShimConfig.matchModules(module, ['codemirror', 'rc-', '@mui']);
},
},
vendor_others: {
name: 'vendor_others',
filename: 'vendor.others.js',
chunks: 'all',
reuseExistingChunk: true,
priority: 6,
minChunks: 2,
enforce: true,
test(module) {
return webpackShimConfig.isExternal(module);
},
},
secondary: {
name: 'pgadmin_commons',
filename: 'pgadmin_commons.js',
chunks: 'all',
priority: 5,
minChunks: 2,
enforce: true,
test(module) {
return webpackShimConfig.isPgAdminLib(module);
},
},
browser_nodes: {
name: 'browser_nodes',
filename: 'browser_nodes.js',
chunks: 'all',
priority: 4,
minChunks: 2,
enforce: true,
test(module) {
return webpackShimConfig.isBrowserNode(module);
},
},
},
},
},
// Define list of Plugins used in Production or development mode
// Ref:https://webpack.js.org/concepts/plugins/#components/sidebar/sidebar.jsx
plugins: PRODUCTION ? [
extractStyle,
providePlugin,
sourceMapDevToolPlugin,
bundleAnalyzer,
copyFiles,
]: [
extractStyle,
providePlugin,
sourceMapDevToolPlugin,
copyFiles,
],
}];