From 83d38211387791efdaed24f167a9d79eaa2fdaf5 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> Date: Tue, 4 Apr 2023 19:17:23 +0530 Subject: Merging similar scripts (and shared modules) with the same runtime into a single content_script entry. --- .../create-manifest-webpack-plugin/index.js | 35 +++++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'config/webpack/plugins/create-manifest-webpack-plugin/index.js') 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 }); } } -- cgit v1.2.3