aboutsummaryrefslogtreecommitdiffstats
path: root/config/webpack/plugins/create-manifest-webpack-plugin/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'config/webpack/plugins/create-manifest-webpack-plugin/index.js')
-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)));
}
);
});