https://github.com/nhn/tui.webpack.safe-umd-plugin
Webpack plugin to handle optional dependencies safely when using libraryTarget: umd
https://github.com/nhn/tui.webpack.safe-umd-plugin
plugin tui umd webpack
Last synced: 2 months ago
JSON representation
Webpack plugin to handle optional dependencies safely when using libraryTarget: umd
- Host: GitHub
- URL: https://github.com/nhn/tui.webpack.safe-umd-plugin
- Owner: nhn
- Created: 2017-07-05T02:52:23.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-06-27T05:59:13.000Z (about 8 years ago)
- Last Synced: 2025-06-12T05:22:13.285Z (about 1 year ago)
- Topics: plugin, tui, umd, webpack
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 10
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
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()
]
}
```