Libraries that have both CommonJs and AMD definitions

I have a library that has the following definition:

(function (root, factory) {
    if (typeof module === "object" && module.exports) {
        // Node, or CommonJS-Like environments
        module.exports = factory(require("lodash"), require("conduitjs"), this);
    } else if (typeof define === "function" && define.amd) {
        // AMD. Register as an anonymous module.
        define(["lodash", "conduitjs"], function (_, Conduit) {
            return factory(_, Conduit, root);
        });
    } else {
        // Browser globals
        root.postal = factory(root._, root.Conduit, root);
    }
}(this, function (_, Conduit, global, undefined)

When WebPack detects these definitions, it includes both (webpack)/buildin/amd-options.js and (webpack)/buildin/module.js. I get that its doing this because both CommonJs and AMD are at play, but I don’t get why they are needed in the first place given that WebPack supports these (with my normal modules) without the need for this.

Author: Fantashit

1 thought on “Libraries that have both CommonJs and AMD definitions

  1. Blame the module…

    Here is a config that disables AMD for all node_modules:

    module: {
      loaders: [
        { test: /node_modules/, loader: "imports?define=>undefined" }
      ]
    }

Comments are closed.