Bootstrap: support native es6 module loading

Created on 22 Aug 2018  路  5Comments  路  Source: twbs/bootstrap

Bootstrap 4.3 (budnle from dist folder) fails when global is null.

From sources:

(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('jquery'), require('popper.js')) :
  typeof define === 'function' && define.amd ? define(['exports', 'jquery', 'popper.js'], factory) :
  (factory((global.bootstrap = {}),global.jQuery,global.Popper));
}(this, (function (exports,$,Popper) {...});

There this from next line can't be null since we will get an excpetion on global.bootstrap = {}

And there are situations when this can be null during loading e.g. importing using native module support:

```

```

Check sources of jquery. They support this new type of loading by checking (this==null)?window:this.

feature js v4

Most helpful comment

About that we should ship an ESM version of Bootstrap

All 5 comments

About that we should ship an ESM version of Bootstrap

It seems it was rollup problem
Now when you have updated rollup.js code looks like

(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('jquery'), require('popper.js')) :
  typeof define === 'function' && define.amd ? define(['exports', 'jquery', 'popper.js'], factory) :
  (global = global || self, factory(global.bootstrap = {}, global.jQuery, global.Popper));
}(this, function (exports, $, Popper) { 'use strict';

so there we have global = global || self

Self there is Window.self (HTML5) ... I've not tested how it works, but I could propose other problem would be to obtain global.Popper (global.jQuery is ok)

you will find that popper esm register itself as global.popper (low case)

Hmm yep, that's why I think we should ship an ESM version of Bootstrap not just UMD

Sorry to interject, but does this mean bootstrap can't be built with an ES module bundler like Rollup?

Hi @KayakinKoder absolutly not, Rollup or Webpack prefer ESM build but if there is no ESM build they use the UMD one (for Bootstrap) 馃槈

BTW this issue is solved by: https://github.com/twbs/bootstrap/pull/28386

And will be in our v5

Was this page helpful?
0 / 5 - 0 ratings