aboutsummaryrefslogtreecommitdiffstats
path: root/config/webpack/plugins
diff options
context:
space:
mode:
authorArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-04-04 16:05:48 +0530
committerArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-04-04 16:05:48 +0530
commit7455c1e81dd18a898004c398a16e9f0b6f7c19ae (patch)
tree364f25f1f55d95131ffbe484cd5836f711d357c0 /config/webpack/plugins
parent5f23f07d04073c06af530332c2d75b48d6c023a0 (diff)
downloadbanglar-bhumi-utils-7455c1e81dd18a898004c398a16e9f0b6f7c19ae.tar.gz
banglar-bhumi-utils-7455c1e81dd18a898004c398a16e9f0b6f7c19ae.zip
Keeping track of the number of times that a shared module has been used and dertermining if it is to be included along with the other scripts.
Diffstat (limited to 'config/webpack/plugins')
-rw-r--r--config/webpack/plugins/create-manifest-webpack-plugin/index.js20
1 files changed, 12 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 a2040da..103fb3c 100644
--- a/config/webpack/plugins/create-manifest-webpack-plugin/index.js
+++ b/config/webpack/plugins/create-manifest-webpack-plugin/index.js
@@ -8,6 +8,10 @@ const sharedModules = webpackRequire("utils/shared-modules");
const manifest = webpackRequire("plugins/create-manifest-webpack-plugin/manifest-template.json");
class CreateManifestPlugin {
+ constructor({ sharedModulesImportedCount }) {
+ this.sharedModulesImportedCount = sharedModulesImportedCount;
+ }
+
apply(compiler) {
compiler.hooks.compilation.tap("CreateManifestPlugin", compilation => {
compilation.hooks.processAssets.tap(
@@ -20,6 +24,14 @@ class CreateManifestPlugin {
manifest.version = require(path.resolve(ROOT_DIR, "package.json")).version;
manifest.content_scripts = [];
+ manifest.content_scripts.push({
+ matches: [`*://banglarbhumi.gov.in/BanglarBhumi/*`],
+ js: sharedModules
+ .filter(sharedModule => this.sharedModulesImportedCount[sharedModule] > 0)
+ .map(sharedModule => `shared/${getFileNameHash(sharedModule, "shared")}.js`),
+ run_at: "document_start"
+ });
+
for (const scriptPath in scripts) {
for (const scriptType in scripts[scriptPath]) {
const matches = [`*://banglarbhumi.gov.in/BanglarBhumi/${scriptPath}`];
@@ -35,14 +47,6 @@ class CreateManifestPlugin {
}
}
- for (const sharedModule of sharedModules) {
- manifest.content_scripts.push({
- matches: [`*://banglarbhumi.gov.in/BanglarBhumi/*`],
- js: [`shared/${getFileNameHash(sharedModule, "shared")}.js`],
- run_at: "document_start"
- });
- }
-
const resources = [];
for (const assetName in assets) {