# safe-umd-webpack-plugin

> Webpack plugin to handle optional dependency safely when using libraryTarget: umd

Latest version **4.0.0** (published 2018-06-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install safe-umd-webpack-plugin
pnpm add safe-umd-webpack-plugin
yarn add safe-umd-webpack-plugin
bun add safe-umd-webpack-plugin
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2018-06-27 |
| First published | 2017-07-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | FE Development Lab |
| Maintainers | nhnent |

## Links

- npm: https://www.npmjs.com/package/safe-umd-webpack-plugin
- Repository: https://github.com/nhnent/tui.webpack.safe-umd-plugin
- Homepage: https://github.com/nhnent/tui.webpack.safe-umd-plugin#readme
- Issues: https://github.com/nhnent/tui.webpack.safe-umd-plugin/issues
- npm.io page: https://npm.io/package/safe-umd-webpack-plugin

## Dependencies (1)

- [webpack-core](https://npm.io/package/webpack-core.md) ^0.6.9

## Recent versions

- 4.0.0 (latest) — 2018-06-27
- 0.0.2 — 2017-08-10
- 0.0.1 — 2017-07-13

## README

# safe-umd-webpack-plugin

Webpack plugin to handle optional dependencies safely when using `libraryTarget: umd`.

## When to use

When using `umd` as a libraryTarget with config like :

```js
module.exports = {
  entry: './src/index.js',
  output: {
    library: ['my', 'module'],
    libraryTarget: 'umd',
    filename: 'bundle.js'
  },
  externals: {
    'my-ext-module': {
      commonjs: 'my-ext-module',
      commonjs2: 'my-ext-module',
      amd: 'my-ext-module',
      root: ['my', 'ext', 'module']
    }
  }
}; 
```

You can't use optional dependencies for a root (namespace) because of the generated code like :

```js
root["my"] = root["my"] || {}, root["my"]["module"] = factory(root["my"]["ext"]["module"]);
```

This plugin replace code above to safely access the namespace with code like :

```js
root["my"] = root["my"] || {}, root["my"]["module"] = factory(root["my"] && root["my"]["ext"] && root["my"]["ext"]["module"]);
```

## How to use

### Install

```
npm install safe-umd-webpack-plugin --save-dev
```

### Config

```js
// webpack.config.js

var SafeUmdPlugin = require('safe-umd-webpack-plugin');

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

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