safe-umd-webpack-plugin

4.0.0 • Public • Published

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 :

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 :

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 :

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

// webpack.config.js
 
var SafeUmdPlugin = require('safe-umd-webpack-plugin');
 
// ...
module.exports = {
  // ...
  plugins: [
    //...
    new SafeUmdPlugin()
  ]
}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
4.0.030latest

Version History

VersionDownloads (Last 7 Days)Published
4.0.030
0.0.2746
0.0.10

Package Sidebar

Install

npm i safe-umd-webpack-plugin

Weekly Downloads

776

Version

4.0.0

License

MIT

Unpacked Size

5.45 kB

Total Files

5

Last publish

Collaborators

  • nhnent