aboutsummaryrefslogtreecommitdiffstats
path: root/config/webpack/plugins/create-manifest-webpack-plugin
diff options
context:
space:
mode:
authorArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-02-06 19:30:21 +0530
committerArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-02-06 19:30:21 +0530
commitc57a9e3d9e304bd360437f8f732dbc0479376cd7 (patch)
treead9e31238aab26fd7a8ceb54d1424daa79a237c9 /config/webpack/plugins/create-manifest-webpack-plugin
parent1a301791bb621fa01fa76e9403b23fe1f4a120af (diff)
downloadbanglar-bhumi-utils-c57a9e3d9e304bd360437f8f732dbc0479376cd7.tar.gz
banglar-bhumi-utils-c57a9e3d9e304bd360437f8f732dbc0479376cd7.zip
Fixed some bugs... Updated some code...
Diffstat (limited to 'config/webpack/plugins/create-manifest-webpack-plugin')
-rw-r--r--config/webpack/plugins/create-manifest-webpack-plugin/index.js30
1 files changed, 13 insertions, 17 deletions
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)));
}
);
});