# add-module-exports-webpack-plugin

> Add `module.exports` for Babel and TypeScript compiled code

Latest version **3.0.0** (published 2024-04-30) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install add-module-exports-webpack-plugin
pnpm add add-module-exports-webpack-plugin
yarn add add-module-exports-webpack-plugin
bun add add-module-exports-webpack-plugin
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2024-04-30 |
| First published | 2017-12-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 1 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 37 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | webpack-plugin, webpack, add, generate, create, make, module, exports, commonjs, cjs, babel, typescript |

## Links

- npm: https://www.npmjs.com/package/add-module-exports-webpack-plugin
- Repository: https://github.com/sindresorhus/add-module-exports-webpack-plugin
- Homepage: https://github.com/sindresorhus/add-module-exports-webpack-plugin#readme
- Issues: https://github.com/sindresorhus/add-module-exports-webpack-plugin/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/add-module-exports-webpack-plugin

## Dependencies (1)

- [webpack-sources](https://npm.io/package/webpack-sources.md) ^2.0.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2024-04-30
- 2.0.0 — 2020-10-14
- 1.0.0 — 2019-04-18
- 0.2.0 — 2019-03-19
- 0.1.0 — 2017-12-07

## README

> [!WARNING]
> Deprecated. Prefer using JavaScript Modules instead of CommonJS.

# add-module-exports-webpack-plugin

> Add `module.exports` for Babel and TypeScript compiled code

When you use ES2015 modules with Babel or have a default export in TypeScript, they generate code which requires you to import it with `require('x').default` in CommonJS instead of `require('x')`. This plugin enables the latter.

## Install

```
$ npm install add-module-exports-webpack-plugin
```

## Usage

```js
const AddModuleExportsPlugin = require('add-module-exports-webpack-plugin');

module.exports = {
	// …
	output: {
		filename: 'dist/index.js',
		libraryTarget: 'commonjs2'
	},
	plugins: [
		new AddModuleExportsPlugin()
	]
};
```

**`output.libraryTarget` must be `commonjs2`**

### Primitive default exports

When exporting a primitive value as default export, other exported values will not be exported anymore. The reason is that this module redeclares the exports as follows.

```js
module.exports.default = (arg1, arg2) => arg1 + arg2;
module.exports.subtract = (arg1, arg2) => arg1 - arg2;
```

This module re-exports them as follows.

```js
module.exports = (arg1, arg2) => arg1 + arg2;
module.exports.default = (arg1, arg2) => arg1 + arg2;
module.exports.subtract = (arg1, arg2) => arg1 - arg2;
```

Because you can't attach properties to a primitive value, it's not possible to re-export the other properties and so you would end up with only a `module.exports`.

## Related

- [node-env-webpack-plugin](https://github.com/sindresorhus/node-env-webpack-plugin) - Simplified `NODE_ENV` handling
- [add-asset-webpack-plugin](https://github.com/sindresorhus/add-asset-webpack-plugin) - Dynamically add an asset to the webpack graph

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