Skip to content

Commit fe68f65

Browse files
author
boyantonchev
committed
GDB-12871: Bundle plugins for loading optimization
## What - Replace per-plugin packaging with a single bundled file. - Update the plugins manifest to describe the bundled package instead of individual plugins. ## Why Previously, each plugin required its own network request. Bundling reduces this to a single request, improving load performance. ## How A script was added that iterates through all plugin modules and collects them into an array. It then creates a module with a register function, which loops over the array of plugin modules and registers each one in sequence. This PR changes the webpack configuration to bundle all plugins into a single file for easier loading. It replaces the previous approach of generating individual plugin entry points using glob patterns with a new bundled approach using a central plugins-bundle.js file that auto-discovers and registers all plugins. Modified webpack config to use a single entry point instead of glob-based individual plugin files Created a new plugins bundle file with auto-discovery functionality for plugin registration Updated webpack optimization settings to prevent code splitting
1 parent 7bca9ad commit fe68f65

File tree

4 files changed

+46
-691
lines changed

4 files changed

+46
-691
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"pre:document": "rimraf -g docs/[!resource]*",
1515
"post:document": "node scripts/post-jsdoc.js",
1616
"document": "npm run pre:document && jsdoc -c jsdoc.config.json && npm run post:document",
17-
"build": "npm run validate-manifest && webpack --config webpack.config.js",
17+
"build": "webpack --config webpack.config.js",
1818
"validate-manifest": "node scripts/validate-manifest.js",
1919
"validate-guides-translations": "node scripts/validate-guides-translations.mjs",
2020
"lint": "eslint .",

plugins/plugins-bundle.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Auto-discover and register all plugins without manual imports.
2+
const ctx = import.meta.webpackContext('./', {
3+
recursive: true,
4+
// Exclude this file; include only \*.js
5+
regExp: /^(?!.*\/?plugins-bundle\.js$).*\.js$/,
6+
mode: 'sync'
7+
});
8+
9+
// Resolve a usable register function from various export styles.
10+
function resolveRegister(mod) {
11+
if (typeof mod === 'function') {
12+
return mod;
13+
}
14+
if (mod && typeof mod.register === 'function') {
15+
return mod.register;
16+
}
17+
if (mod && typeof mod.default === 'function') {
18+
return mod.default;
19+
}
20+
if (mod && mod.default && typeof mod.default.register === 'function') {
21+
return mod.default.register;
22+
}
23+
return null;
24+
}
25+
26+
// Gather all register functions in a stable order.
27+
const registerFns = ctx.keys()
28+
.sort()
29+
.map((k) => resolveRegister(ctx(k)))
30+
.filter(Boolean);
31+
32+
// Public API: register all discovered plugins.
33+
export function register(registry) {
34+
for (const register of registerFns) register(registry);
35+
}
36+

0 commit comments

Comments
 (0)