aboutsummaryrefslogtreecommitdiffstats
path: root/config/webpack/plugins
diff options
context:
space:
mode:
authorArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-02-08 18:51:39 +0530
committerArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-02-08 18:51:39 +0530
commit915947e3e7ab7c1fa07596ab4b13bf6e1cc50b76 (patch)
tree8e8a7137d2177dc52da83a5af9e8f7b442ed4a71 /config/webpack/plugins
parent4993aaf41e132dd0805bf6c487901d9f2aecfcfe (diff)
downloadbanglar-bhumi-utils-915947e3e7ab7c1fa07596ab4b13bf6e1cc50b76.tar.gz
banglar-bhumi-utils-915947e3e7ab7c1fa07596ab4b13bf6e1cc50b76.zip
Cleaned code.
Diffstat (limited to 'config/webpack/plugins')
-rw-r--r--config/webpack/plugins/create-manifest-webpack-plugin/index.js11
-rw-r--r--config/webpack/plugins/inject-script-webpack-plugin.js33
-rw-r--r--config/webpack/plugins/sanitize-scripts-import-webpack-plugin.js10
3 files changed, 19 insertions, 35 deletions
diff --git a/config/webpack/plugins/create-manifest-webpack-plugin/index.js b/config/webpack/plugins/create-manifest-webpack-plugin/index.js
index 4a07380..6bbb485 100644
--- a/config/webpack/plugins/create-manifest-webpack-plugin/index.js
+++ b/config/webpack/plugins/create-manifest-webpack-plugin/index.js
@@ -1,3 +1,4 @@
+const { sources } = require("webpack");
const path = require("path");
const { version } = require(path.resolve(process.env.ROOT_DIR, "package.json"));
@@ -34,10 +35,10 @@ class CreateManifestPlugin {
compilation.hooks.processAssets.tap(
{
name: "CreateManifestPlugin",
- stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_ADDITIONAL,
additionalAssets: true
},
- assets => {
+ () => {
this.manifest.version = version;
this.manifest.content_scripts = []
@@ -64,8 +65,10 @@ class CreateManifestPlugin {
}
}
- const { RawSource } = compiler.webpack.sources;
- assets["manifest.json"] = new RawSource(Buffer.from(JSON.stringify(this.manifest)));
+ compilation.updateAsset(
+ "manifest.json",
+ new sources.RawSource(JSON.stringify(this.manifest))
+ );
}
);
});
diff --git a/config/webpack/plugins/inject-script-webpack-plugin.js b/config/webpack/plugins/inject-script-webpack-plugin.js
index 6568514..213e691 100644
--- a/config/webpack/plugins/inject-script-webpack-plugin.js
+++ b/config/webpack/plugins/inject-script-webpack-plugin.js
@@ -1,23 +1,6 @@
const { sources } = require("webpack");
const terser = require("terser");
-const propectualIndexOf = (string, characterList, start) => {
- if (start > 0) {
- let i = 0;
- let x = start;
- while (i < characterList.length) {
- x = string.indexOf(characterList[i], x + 1);
- if (x < 0) {
- return -1;
- }
- i++;
- }
- return x;
- } else {
- return -1;
- }
-};
-
class InjectScriptPlugin {
constructor({ onload, isFirst }) {
this.onload = !!onload;
@@ -36,11 +19,11 @@ class InjectScriptPlugin {
for (const assetName in assets) {
if (assetName.endsWith(".js")) {
let currentAssetContent = compilation.getAsset(assetName).source.source();
- let start = `
- const observer = new MutationObserver(mutations => {
- const script = document.querySelector("head > script:nth-child(54)");
- if (script) {
- script.innerHTML
+ let start = `(() => {
+ const o = new MutationObserver(() => {
+ const s = document.querySelector("head > script:nth-child(54)");
+ if (s) {
+ s.innerHTML
`;
let end = "";
if (!this.isFirst) {
@@ -52,11 +35,11 @@ class InjectScriptPlugin {
end += "});";
}
end += `\`;
- observer.disconnect();
+ o.disconnect();
}
});
- observer.observe(document, {childList: true, subtree: true});
- `;
+ o.observe(document, {childList: true, subtree: true});
+ })();`;
const content = (await terser.minify(currentAssetContent.replaceAll("`", "\\`"))).code;
compilation.updateAsset(
assetName,
diff --git a/config/webpack/plugins/sanitize-scripts-import-webpack-plugin.js b/config/webpack/plugins/sanitize-scripts-import-webpack-plugin.js
index 61ce804..37c2cf4 100644
--- a/config/webpack/plugins/sanitize-scripts-import-webpack-plugin.js
+++ b/config/webpack/plugins/sanitize-scripts-import-webpack-plugin.js
@@ -1,15 +1,13 @@
const { sources } = require("webpack");
-const propectualIndexOf = (string, characterList, start) => {
+const perpectualIndexOf = (string, characterList, start) => {
if (start > 0) {
- let i = 0;
let x = start;
- while (i < characterList.length) {
+ for (let i = 0; i < characterList.length; i++) {
x = string.indexOf(characterList[i], x + 1);
if (x < 0) {
return -1;
}
- i++;
}
return x;
} else {
@@ -33,8 +31,8 @@ class SanitizeScriptsImportPlugin {
let previouslyEnded = 0;
let code = "";
while (true) {
- const start = propectualIndexOf(currentAssetContent, ["\n/***/", "\n/***/", "\n"], previouslyEnded + 1);
- previouslyEnded = propectualIndexOf(currentAssetContent, ["\n/***/"], start + 1);
+ const start = perpectualIndexOf(currentAssetContent, ["\n/***/", "\n/***/", "\n"], previouslyEnded + 1);
+ previouslyEnded = perpectualIndexOf(currentAssetContent, ["\n/***/"], start + 1);
if (previouslyEnded < 0) {
break;
} else {