diff options
| author | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-04-08 11:46:35 +0530 |
|---|---|---|
| committer | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-04-08 11:46:35 +0530 |
| commit | ccf73485cfba952451144d7841cbb3fac8368867 (patch) | |
| tree | 642b374684afa6ad4446af556fd98f118609d5c7 /config/webpack/plugins/create-manifest-webpack-plugin | |
| parent | c59c25bff510166011471b136d12c4217f844eb9 (diff) | |
| download | banglar-bhumi-utils-ccf73485cfba952451144d7841cbb3fac8368867.tar.gz banglar-bhumi-utils-ccf73485cfba952451144d7841cbb3fac8368867.zip | |
Injecting shared modules for the injected scripts, further reusing code.
Diffstat (limited to 'config/webpack/plugins/create-manifest-webpack-plugin')
| -rw-r--r-- | config/webpack/plugins/create-manifest-webpack-plugin/index.js | 25 |
1 files changed, 17 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 2187a05..91ddf3e 100644 --- a/config/webpack/plugins/create-manifest-webpack-plugin/index.js +++ b/config/webpack/plugins/create-manifest-webpack-plugin/index.js @@ -7,8 +7,9 @@ const scripts = webpackRequire("utils/scripts"); const manifest = webpackRequire("plugins/create-manifest-webpack-plugin/manifest-template.json"); class CreateManifestPlugin { - constructor({ sharedModulesImportedCount, sortedSharedModules }) { + constructor({ sharedModulesImportedCount, injectedSharedModulesImportedCount, sortedSharedModules }) { this.sharedModulesImportedCount = sharedModulesImportedCount; + this.injectedSharedModulesImportedCount = injectedSharedModulesImportedCount; this.sortedSharedModules = sortedSharedModules; } @@ -17,8 +18,7 @@ class CreateManifestPlugin { compilation.hooks.processAssets.tap( { name: "CreateManifestPlugin", - stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ANALYSE, - additionalAssets: true + stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL }, assets => { manifest.version = require(path.resolve(ROOT_DIR, "package.json")).version; @@ -33,12 +33,12 @@ class CreateManifestPlugin { const scriptRuntime = getScriptRuntimeFromType(scriptType); if (typeof arrangedScripts[scriptPath][scriptRuntime] === "undefined") { - arrangedScripts[scriptPath][scriptRuntime] = []; - } + arrangedScripts[scriptPath][scriptRuntime] = []; + } - arrangedScripts[scriptPath][scriptRuntime].push(`scripts/${getFileNameHash(scriptType, scriptPath)}.js`); + arrangedScripts[scriptPath][scriptRuntime].push(`scripts/${getFileNameHash(scriptType, scriptPath)}.js`); + } } - } manifest.content_scripts.push({ matches: [`*://banglarbhumi.gov.in/BanglarBhumi/*`], @@ -66,7 +66,7 @@ class CreateManifestPlugin { } } - const resources = []; + let resources = []; for (const assetName in assets) { if (/^assets\/.*\.(jpg|png|gif)$/.test(assetName)) { @@ -74,6 +74,15 @@ class CreateManifestPlugin { } } + const injectedSharedModules = this.sortedSharedModules + .filter(sharedModule => this.injectedSharedModulesImportedCount[sharedModule] > 0) + .map(sharedModule => `shared/${getFileNameHash(sharedModule, "shared")}.js`); + + if (injectedSharedModules.length > 0) { + resources = resources.concat(injectedSharedModules); + manifest.content_scripts[0].js.unshift(`shared/${getFileNameHash("injected-shared-modules", "shared")}.js`); + } + if (resources.length > 0) { manifest.web_accessible_resources = [ { |
