3

I am webpack newbie, so I apologize in advance if I am trying to use Webpack for something it isn't made for.

I am publishing my first library with webpack. I have tons of UMD modules in my project and in node (or commonjs) environment I want to keep the directory structure, while in browser environment I want to bundle all the modules together into one bundle. My question is how do I achieve that. When I have something like this in my entry file -

(function(root, factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD. Register as an anonymous module.
        define(['metaAnalytics'], factory);
    } else if (typeof module === 'object' && module.exports) {
        // Node. Does not work with strict CommonJS, but
        // only CommonJS-like environments that support module.exports,
        // like Node.
        module.exports = factory(require('./AnalyticsNode.js'));
    } else {
        // Browser globals (root is window)
        root.metaAnalytics = factory(require('./AnalyticsBrowser.js'));
    }
}(this, function(DAClient) {
    //do something with DAClient
}));

And I pass the above file through webpack it doesn't bring in the code from dependencies into the output file. How can I make webpack automatically pack AnalyticsBrowser.js and all its dependencies into one bundle? Is that possible?

Note - I removed the UMD wrapper and replaced them with a simple require statement and webpack was able to compile code from it into the output. So my question is why it can't compile dependencies to a UMD module into the output file.

Mishra
  • 85
  • 3
  • 9

0 Answers0