From c57a9e3d9e304bd360437f8f732dbc0479376cd7 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> Date: Mon, 6 Feb 2023 19:30:21 +0530 Subject: Fixed some bugs... Updated some code... --- .../create-manifest-webpack-plugin/index.js | 30 ++++++++++------------ 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'config/webpack/plugins/create-manifest-webpack-plugin') diff --git a/config/webpack/plugins/create-manifest-webpack-plugin/index.js b/config/webpack/plugins/create-manifest-webpack-plugin/index.js index 2ab2721..fade66d 100644 --- a/config/webpack/plugins/create-manifest-webpack-plugin/index.js +++ b/config/webpack/plugins/create-manifest-webpack-plugin/index.js @@ -2,20 +2,17 @@ const path = require("path"); const { version } = require(path.resolve(process.env.ROOT_DIR, "package.json")); -const scriptTypeRunAtMap = { - injected: "document_start", - rendered: "document_end", - loaded: "document_idle" -}; - class CreateManifestPlugin { constructor(scripts) { - this.scripts = scripts; + this.scripts = {}; this.manifest = require("./manifest-template.json"); - this.scripts.injected = this.scripts.injected - ? { ...this.scripts.injected, ...(this.scripts.injected_and_loaded || {}) } - : this.scripts.injected_and_loaded; - this.scripts.injected_and_loaded = undefined; + this.scripts.document_start = { + ...(scripts.before || {}), + ...(scripts.injected || {}), + ...(scripts.injected_and_loaded || {}) + }; + this.scripts.document_end = scripts.rendered || {}; + this.scripts.document_idle = scripts.loaded || {}; } apply(compiler) { @@ -30,19 +27,18 @@ class CreateManifestPlugin { this.manifest.version = version; this.manifest.content_scripts = [] - for (const scriptType in scriptTypeRunAtMap) { - if (this.scripts[scriptType]) { + for (const scriptType in this.scripts) { + if (Object.keys(this.scripts[scriptType]).length > 0) { this.manifest.content_scripts.push({ matches: ["https://banglarbhumi.gov.in/*", "http://banglarbhumi.gov.in/*"], - js: Object.keys(this.scripts[scriptType]), - run_at: scriptTypeRunAtMap[scriptType] + js: Object.keys(this.scripts[scriptType]).map(scriptName => `${scriptName}.js`), + run_at: scriptType }); } } - const encoder = new TextEncoder("UTF-8"); const { RawSource } = compiler.webpack.sources; - assets["manifest.json"] = new RawSource(Buffer.from(encoder.encode(JSON.stringify(this.manifest).buffer))); + assets["manifest.json"] = new RawSource(Buffer.from(JSON.stringify(this.manifest))); } ); }); -- cgit v1.2.3