execute injecting logic only in UMD bundle

90 Views Asked by At

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

2

There are 2 best solutions below

0
On BEST ANSWER

Solution:

umd.js (umd bundle handler)

window.isUmdBundle = true;

index.js (module bundle handler)

window.isUmdBundle = false;

component.js

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

As nwb allows us to use webpack configuration. I think a good way is to pass similar to in webpack.config

I would add to nwb.config.js

webpack: {
    extra: {
        externals: {
            // Use external version of Jodit
            jodit: 'Jodit',
        }
    }
 }