aboutsummaryrefslogtreecommitdiffstats
path: root/config/webpack/plugins
diff options
context:
space:
mode:
authorArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-04-04 19:17:23 +0530
committerArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-04-04 19:17:23 +0530
commit83d38211387791efdaed24f167a9d79eaa2fdaf5 (patch)
tree0946d949c12ab851dddce4f72346ee4d46af0b8e /config/webpack/plugins
parent6bc8d472a556774630e4432141d5ef9f8ea68c59 (diff)
downloadbanglar-bhumi-utils-83d38211387791efdaed24f167a9d79eaa2fdaf5.tar.gz
banglar-bhumi-utils-83d38211387791efdaed24f167a9d79eaa2fdaf5.zip
Merging similar scripts (and shared modules) with the same runtime into a single content_script entry.
Diffstat (limited to 'config/webpack/plugins')
-rw-r--r--config/webpack/plugins/create-manifest-webpack-plugin/index.js35
1 files changed, 27 insertions, 8 deletions
diff --git a/config/webpack/plugins/create-manifest-webpack-plugin/index.js b/config/webpack/plugins/create-manifest-webpack-plugin/index.js
index b4a29a3..667f1de 100644
--- a/config/webpack/plugins/create-manifest-webpack-plugin/index.js
+++ b/config/webpack/plugins/create-manifest-webpack-plugin/index.js
@@ -24,25 +24,44 @@ class CreateManifestPlugin {
manifest.version = require(path.resolve(ROOT_DIR, "package.json")).version;
manifest.content_scripts = [];
+ const arrangedScripts = {};
+
+ for (const scriptPath in scripts) {
+ arrangedScripts[scriptPath] = {};
+
+ for (const scriptType in scripts[scriptPath]) {
+ const scriptRuntime = getScriptRuntimeFromType(scriptType);
+
+ if (typeof arrangedScripts[scriptPath][scriptRuntime] === "undefined") {
+ arrangedScripts[scriptPath][scriptRuntime] = [];
+ }
+
+ arrangedScripts[scriptPath][scriptRuntime].push(`scripts/${getFileNameHash(scriptType, scriptPath)}.js`);
+ }
+ }
+
manifest.content_scripts.push({
matches: [`*://banglarbhumi.gov.in/BanglarBhumi/*`],
js: this.sortedSharedModules
.filter(sharedModule => this.sharedModulesImportedCount[sharedModule] > 0)
- .map(sharedModule => `shared/${getFileNameHash(sharedModule, "shared")}.js`),
+ .map(sharedModule => `shared/${getFileNameHash(sharedModule, "shared")}.js`)
+ .concat(arrangedScripts["*"]["document_start"]),
run_at: "document_start"
});
- for (const scriptPath in scripts) {
- for (const scriptType in scripts[scriptPath]) {
- const matches = [`*://banglarbhumi.gov.in/BanglarBhumi/${scriptPath}`];
+ delete arrangedScripts["*"]["document_start"];
+
+ for (const scriptPath in arrangedScripts) {
+ const matches = [`*://banglarbhumi.gov.in/BanglarBhumi/${scriptPath}`];
- if (scriptPath === "Home")
- matches.push(`*://banglarbhumi.gov.in/BanglarBhumi/${scriptPath}.action`);
+ if (scriptPath === "Home")
+ matches.push(`*://banglarbhumi.gov.in/BanglarBhumi/${scriptPath}.action`);
+ for (const scriptRuntime in arrangedScripts[scriptPath]) {
manifest.content_scripts.push({
matches,
- js: [`scripts/${getFileNameHash(scriptType, scriptPath)}.js`],
- run_at: getScriptRuntimeFromType(scriptType)
+ js: arrangedScripts[scriptPath][scriptRuntime],
+ run_at: scriptRuntime
});
}
}