reactjsumdnwb

execute injecting logic only in UMD bundle


I use react nwb toolkit for my lib, I also uses UMD bundles.

So for UMD bundle size optimize, I inject one of components through "script" tag, and this injecting needed only when use the UMD bundle, because in normal lib this lib comes from dependencies.

How I can do this? May be there is some "process" variable, which will "say" it's a UMD build.

code


Solution

  • Solution:

    umd.js (umd bundle handler)

    window.isUmdBundle = true;
    

    index.js (module bundle handler)

    window.isUmdBundle = false;
    

    component.js

    if(window.isUmdBundle) {
       // ...code
    }