Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Tool:webpack

From ReverseEngineering.wiki
Tool
On this wiki Facts · Code · Notes · Topics

webpack (MIT) is the most common JavaScript bundler; its output is a table of module functions plus a small runtime (__webpack_require__) and, for split builds, a global webpackChunk<name> array that chunk files push into.

Output structure

The main bundle (read in lib/javascript/JavascriptModulesPlugin.js) declares var __webpack_modules__ = ({ id: function(module, exports, __webpack_require__){...}, ... }) and a cache var __webpack_module_cache__ = {}. __webpack_require__(moduleId) returns the cached exports if present, else creates { id, loaded, exports: {} }, stores it in the cache and runs __webpack_modules__[moduleId](module, module.exports, __webpack_require__). The map and the cache are also exposed as __webpack_require__.m and __webpack_require__.c when something needs them. Module ids are numbers (production default, optimised ids) or path-like strings (development).

Runtime helpers (names are fixed by RuntimeGlobals)

Name Meaning
__webpack_require__.m / .c module factories / module cache
.o hasOwnProperty
.d define getters on exports (ES module live bindings)
.r mark exports as an ES module (__esModule, Symbol.toStringTag Module)
.n default-export compatibility getter
.t fake namespace object
.e / .f / .u ensure (load) chunk / chunk handlers / chunk file name function
.p public path
.l load script
.O on-chunks-loaded (entry waits for chunk ids)
.x startup
.i interceptModuleExecution
.S share scope map (Module Federation)

The .d, .r, .o calls at the top of each module tell you its exports; n.d(t, { Foo: () => a }) maps exported names to local mangled ones, so export names survive minification.

Chunks (splitChunks, dynamic import)

A non-entry chunk file is (self["webpackChunk<uniqueName>"] = self["webpackChunk<uniqueName>"] || []).push([[chunkIds], { moduleId: function..., ... }, optionalRuntimeFunction]). The default global name is webpackChunk plus the unique name (from output.uniqueName, in practice the package name) in lib/config/defaults.js. The runtime replaces the array's push with a callback (webpackJsonpCallback) and replays the entries already in it; installedChunks[chunkId] === 0 means loaded. The optional third element is a function taking __webpack_require__ that runs runtime modules and entry startup. Older versions used webpackJsonp (Unverified).

To reconstruct a full app, collect the module maps of all chunk files into one table keyed by module id; ids are global across chunks of one build.

Analysis tips

  • Search for string constants, .d( export maps and .p public path values to find modules.
  • lib/config/target.js (commit 58ecc95f5db98d5caed89b6b12e809e774d6448f, lines 405-427) defines the targets electron[X[.Y]]-main|preload|renderer; for -main it sets node: true, web: false, require: true, document: false, so lib/config/defaults.js (lines 2044-2062) picks chunkLoading "require" for the commonjs chunk format, and "jsonp" only when the target has a document (the renderer). Main-process bundles therefore load chunks with require.
  • A .map file recovers module paths such as webpack://name/./src/foo.js: see Format:Source map (v3).

See Technique:Reversing bundled JavaScript.

Code & repositories

  • https://github.com/webpack/webpack (MIT), runtime in lib/runtime, bundle template in lib/javascript.
  • https://github.com/webpack/webpack @ e1c10dc15e8df3a7efa16ff0ddb3a2ad84381600 · license: MIT (read from LICENSE; GitHub's API was busy)
    Bundler; runtime templates in lib/runtime and bundle template in lib/javascript.
    Tested on: source read, not run: read only · checked 2026-10-18