aboutsummaryrefslogtreecommitdiffstats
path: root/config/webpack/plugins/create-manifest-webpack-plugin/index.js
diff options
context:
space:
mode:
authorArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-02-13 22:49:42 +0530
committerArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-02-13 22:49:42 +0530
commit34ad953c953a395ba3e51c8125034a6bb65b2a79 (patch)
tree253cc30047bb3963f387bd340d50938b3b727053 /config/webpack/plugins/create-manifest-webpack-plugin/index.js
parentaeeabaa0050ecb9e43b1a3fb309f314d92d3ca97 (diff)
downloadbanglar-bhumi-utils-34ad953c953a395ba3e51c8125034a6bb65b2a79.tar.gz
banglar-bhumi-utils-34ad953c953a395ba3e51c8125034a6bb65b2a79.zip
Fixed not being able to import modules in scripts.
Diffstat (limited to 'config/webpack/plugins/create-manifest-webpack-plugin/index.js')
-rw-r--r--config/webpack/plugins/create-manifest-webpack-plugin/index.js50
1 files changed, 14 insertions, 36 deletions
diff --git a/config/webpack/plugins/create-manifest-webpack-plugin/index.js b/config/webpack/plugins/create-manifest-webpack-plugin/index.js
index 7852d62..3a16770 100644
--- a/config/webpack/plugins/create-manifest-webpack-plugin/index.js
+++ b/config/webpack/plugins/create-manifest-webpack-plugin/index.js
@@ -1,22 +1,11 @@
const { sources } = require("webpack");
const path = require("path");
-const scripts = require(path.resolve(SOURCE_DIR, "scripts.json"));
-
-const { version } = require(path.resolve(ROOT_DIR, "package.json"));
const { getScriptRuntimeFromType } = webpackRequire("utils/script-runtime");
const { getFileNameHash } = webpackRequire("utils/file-name-hash");
+const { formatScripts } = webpackRequire("utils/format-scripts");
class CreateManifestPlugin {
- constructor() {
- this.scripts = {};
- this.manifest = webpackRequire("plugins/create-manifest-webpack-plugin/manifest-template.json");
- for (const scriptType in scripts) {
- const scriptRuntime = getScriptRuntimeFromType(scriptType);
- this.scripts[scriptRuntime] = { ...this.scripts[scriptRuntime], ...scripts[scriptType] };
- }
- }
-
apply(compiler) {
compiler.hooks.compilation.tap("CreateManifestPlugin", compilation => {
compilation.hooks.processAssets.tap(
@@ -26,35 +15,24 @@ class CreateManifestPlugin {
additionalAssets: true
},
() => {
- this.manifest.version = version;
- this.manifest.content_scripts = []
-
- for (const scriptRuntime in this.scripts) {
- if (Object.keys(this.scripts[scriptRuntime]).length > 0) {
- const currentScripts = this.scripts[scriptRuntime];
-
- let paths = {};
- for (const scriptName in currentScripts) {
- const scriptPath = currentScripts[scriptName];
- if (!path[scriptPath]) {
- paths[scriptPath] = [];
- }
- paths[scriptPath].push(scriptName);
- }
-
- for (const scriptPath in paths) {
- this.manifest.content_scripts.push({
- matches: [`*://banglarbhumi.gov.in/${scriptPath}`],
- js: [`scripts/${getFileNameHash(scriptPath)}/${scriptRuntime}.js`],
- run_at: scriptRuntime
- });
- }
+ const scripts = formatScripts(require(path.resolve(SOURCE_DIR, "scripts.json")));
+ const manifest = webpackRequire("plugins/create-manifest-webpack-plugin/manifest-template.json");
+ manifest.version = require(path.resolve(ROOT_DIR, "package.json")).version;
+ manifest.content_scripts = []
+
+ for (const scriptPath in scripts) {
+ for (const scriptType in scripts[scriptPath]) {
+ manifest.content_scripts.push({
+ matches: [`*://banglarbhumi.gov.in/BanglarBhumi/${scriptPath}`],
+ js: [`scripts/${getFileNameHash(scriptPath)}/${scriptType}.js`],
+ run_at: getScriptRuntimeFromType(scriptType)
+ });
}
}
compilation.emitAsset(
"manifest.json",
- new sources.RawSource(JSON.stringify(this.manifest))
+ new sources.RawSource(JSON.stringify(manifest))
);
}
);