WpRequire
is a library for userscripts to interact with Webpack's module chunks. It provides the ability to require Webpack modules and find modules that match a condition, to keep userscripts working through site updates.
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/wprequire.js
const webpack = new WpRequire(webpackChunkname);
// Require a module
const module = webpack(moduleId);
// Find a module
const module = webpack.findModule((m) => Object.hasOwn(m, "createUser"));
// List modules
console.log(webpack.moduleExports);
-
webpackChunk
(Array): The Webpack chunk array. Ifnull
is provided, the constructor will attempt to find it usingWpRequire.findWebpackChunks()
. -
interceptModuleCalls
(Boolean): If true, the constructor intercepts module calls to cache their exports. Default isfalse
. -
Throws:
- Error if Webpack chunks or the require function cannot be found.
Calls wpRequire.require
with provided arguments.
Calls the Webpack require
Calls the Webpack require
function with the provided arguments.
-
condition
(Function): A function that takes module exports as an argument and returns a boolean indicating if the module matches the condition. -
cachedOnly
(Boolean): If true, only searches cached modules. Default isfalse
. -
Returns: The exports of the first module that matches the condition, or
null
if no match is found.
- Returns: An array of Webpack chunk arrays found in the global window object.
An object storing the exports of intercepted modules.
An object representing all the modules in the Webpack bundle.
Getter that requires all modules exports.