Listing a scoped module in a umd build as an external resolves incorrectly

Given a webpack.config.js like this (simplified):

module.exports = {
    output: {
        libraryTarget: "umd",
    },
    externals: {
        '@reactivex/rx': '@reactivex/rx',
    },
};

And a file that contains (simplified):

var Rx = require('@reactivex/rx');

Webpack will produce a build like this:

(function webpackUniversalModuleDefinition(root, factory) {
    if(typeof exports === 'object' && typeof module === 'object')
        module.exports = factory(require("angular"), require("@reactivex/rx"));
    else if(typeof define === 'function' && define.amd)
        define(["angular", "@reactivex/rx"], factory);
    else if(typeof exports === 'object')
        exports["AngularObserve"] = factory(require("angular"), require("@reactivex/rx"));
    else
        root["AngularObserve"] = factory(root["angular"], root["@reactivex/rx"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_3__) {

As you can see for the browser case: root['@reactivex/rx'] is used. However, it is my understanding that this sort of scoped module would typically expose itself as root['rx'].

How can I get around this situation?

Author: Fantashit

1 thought on “Listing a scoped module in a umd build as an external resolves incorrectly

Comments are closed.