# webpack-exposer

> Expose webpack internals objects

Latest version **0.0.3** (published 2018-04-30) · Unlicense license · 0 weekly downloads

## Install

```sh
npm install webpack-exposer
pnpm add webpack-exposer
yarn add webpack-exposer
bun add webpack-exposer
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2018-04-30 |
| First published | 2018-04-30 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Steve Fan |
| Maintainers | stevefan1999 |

## Links

- npm: https://www.npmjs.com/package/webpack-exposer
- Repository: https://github.com/stevefan1999/webpack-exposer
- npm.io page: https://npm.io/package/webpack-exposer

## Recent versions

- 0.0.3 (latest) — 2018-04-30
- 0.0.2 — 2018-04-30

## README

# webpack-exposer

This is a simple module to expose internal `__webpack_<insert name here>__` functions.

Works with webpack >= 2, best suited with `NamedModulesPlugin`

# Explaination

Each webpack module is wrapped with this higher-level function scope:

```js
(function(module, exports, __webpack_require__) {
  var moduleA = __webpack_require__(<name or id>)
  var moduleB = __webpack_require__(<name or id>)
  ...
})

```

`__webpack_require__` is global until an unknown time later. This little hack attempts to recover this behavior by exposing `__webpack_require__` using `arguments` object and the module system:

```js
(function(module, exports, __webpack_require__) {
  (function (module, exports, wr) {
    ...
  })(arguments[0], arguments[1], arguments[2])
})

```

Which the arguments should subsitute equivalently. Then `__webpack_require__` will be global once again, some other objects are also exposed, so there are many rooms for hacking, for example dynamic (external) module loading or module hooking.

I cannot just unwrap this function because I observed only one argument will be available. I don't know the exact reason for this.

# Usage
Just `import` or `require` this file/module in your index/main file:

```js
import 'webpack-exposer'

// equivalently
require('webpack-exposer')
```
If `__webpack_require__` is correctly supplied, `window.__webpack_require__` and `window.require` (and a big list of other things) will be available!

# Ten cents

Add [`NamedModulesPlugin`](https://webpack.js.org/plugins/named-modules-plugin/) to your webpack setup to not get an obscured integer ID, for the sake of easy hacking! This even works for non-HMR/development environment and the result set in `__webpack_modules__` are drastically different!

```js
const { NamedModulesPlugin } = require('webpack')

module.exports = {
  ...
  plugins: [
    ...
    new NamedModulesPlugin()
  ]
}
```

---
_Source: https://npm.io/package/webpack-exposer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
