aboutsummaryrefslogtreecommitdiffstats
path: root/config/webpack/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'config/webpack/plugins')
-rw-r--r--config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js12
-rw-r--r--config/webpack/plugins/create-manifest-webpack-plugin/index.js19
-rw-r--r--config/webpack/plugins/create-rules-webpack-plugin.js8
-rw-r--r--config/webpack/plugins/inject-script-webpack-plugin.js9
4 files changed, 48 insertions, 0 deletions
diff --git a/config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js b/config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js
index 695d4ef..2adb017 100644
--- a/config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js
+++ b/config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js
@@ -4,12 +4,24 @@ import webpack from "webpack";
import { getFileName } from "../utils/build-file.js";
+/**
+ * Webpack plugin that generates an injected shared-modules bundle.
+ * After all assets are processed, it creates a small JS file that
+ * calls the script injector for each shared module that was imported
+ * by injected scripts.
+ */
class CreateInjectedSharedModulesPlugin {
+ /**
+ * @param {{ injectedSharedModulesImportedCount: Record<string, number>, sortedSharedModules: string[] }} options
+ */
constructor({ injectedSharedModulesImportedCount, sortedSharedModules }) {
this.injectedSharedModulesImportedCount = injectedSharedModulesImportedCount;
this.sortedSharedModules = sortedSharedModules;
}
+ /**
+ * @param {import("webpack").Compiler} compiler
+ */
apply(compiler) {
compiler.hooks.compilation.tap("CreateInjectedSharedModulesPlugin", compilation => {
compilation.hooks.processAssets.tap(
diff --git a/config/webpack/plugins/create-manifest-webpack-plugin/index.js b/config/webpack/plugins/create-manifest-webpack-plugin/index.js
index 6f1e2be..f012f1e 100644
--- a/config/webpack/plugins/create-manifest-webpack-plugin/index.js
+++ b/config/webpack/plugins/create-manifest-webpack-plugin/index.js
@@ -11,13 +11,32 @@ const manifest = JSON.parse(
),
);
+/**
+ * Webpack plugin that dynamically generates the extension's
+ * `manifest.json` asset. It reads the template, resolves the
+ * current version from `package.json`, and builds `content_scripts`
+ * entries by matching script definitions from `scripts.json` against
+ * page URL patterns. Shared modules, injected scripts, and
+ * web-accessible resources are added automatically based on import
+ * counts collected during the build.
+ */
class CreateManifestPlugin {
+ /**
+ * @param {{
+ * sharedModulesImportedCount: Record<string, number>,
+ * injectedSharedModulesImportedCount: Record<string, number>,
+ * sortedSharedModules: string[]
+ * }} options
+ */
constructor({ sharedModulesImportedCount, injectedSharedModulesImportedCount, sortedSharedModules }) {
this.sharedModulesImportedCount = sharedModulesImportedCount;
this.injectedSharedModulesImportedCount = injectedSharedModulesImportedCount;
this.sortedSharedModules = sortedSharedModules;
}
+ /**
+ * @param {import("webpack").Compiler} compiler
+ */
apply(compiler) {
compiler.hooks.compilation.tap("CreateManifestPlugin", compilation => {
compilation.hooks.processAssets.tap(
diff --git a/config/webpack/plugins/create-rules-webpack-plugin.js b/config/webpack/plugins/create-rules-webpack-plugin.js
index 5573ddf..55b60f7 100644
--- a/config/webpack/plugins/create-rules-webpack-plugin.js
+++ b/config/webpack/plugins/create-rules-webpack-plugin.js
@@ -2,7 +2,15 @@ import path from "path";
import fs from "fs";
import webpack from "webpack";
+/**
+ * Webpack plugin that reads all JSON rule files from `src/rules/`,
+ * assigns sequential IDs to each rule, and emits a single `rules.json`
+ * asset used by `declarativeNetRequest`.
+ */
class CreateRulesPlugin {
+ /**
+ * @param {import("webpack").Compiler} compiler
+ */
apply(compiler) {
compiler.hooks.compilation.tap("CreateRulesPlugin", compilation => {
compilation.hooks.processAssets.tap(
diff --git a/config/webpack/plugins/inject-script-webpack-plugin.js b/config/webpack/plugins/inject-script-webpack-plugin.js
index 2b60022..43c5d9f 100644
--- a/config/webpack/plugins/inject-script-webpack-plugin.js
+++ b/config/webpack/plugins/inject-script-webpack-plugin.js
@@ -4,7 +4,16 @@ import path from "path";
import { getFileName } from "../utils/build-file.js";
import { getInjectedCode } from "../utils/injected-code.js";
+/**
+ * Webpack plugin that post-processes every `.js` asset to replace
+ * extension-asset URL placeholders with runtime lookup code, and
+ * emits an additional "injected" script that the content script
+ * injects into the page via the script-injector module.
+ */
class InjectScriptPlugin {
+ /**
+ * @param {import("webpack").Compiler} compiler
+ */
apply(compiler) {
compiler.hooks.compilation.tap("InjectScriptPlugin", compilation => {
compilation.hooks.processAssets.tapPromise(