2

I want to transpile ES6 to ES5 since we're forced to support IE11 and have some trouble with modern scripts. My bundle contains Sweetalert2 and window got undefined after babel.

Input

(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
    typeof define === 'function' && define.amd ? define(factory) :
    (global.Sweetalert2 = factory());
}(this, (function () { 'use strict'; 
    // ...

After babel processing:

(function (global, factory) {
  (typeof exports === "undefined" ? "undefined" : _typeof2(exports)) === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : global.Sweetalert2 = factory();
})(void 0, function () {
  'use strict';
// ....

I found How to stop babel from transpiling 'this' to 'undefined' and since the preset-es2015 package is considered as deprecated, I thought that using @babel/preset-env the up2date repalcement for my babel7 is "esmodules": false but it's not working.

.babelrc

{
  "ignore": ["gulpfile.js"],
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "esmodules": false
        }
      }
    ]
  ]
}
user2864740
  • 60,010
  • 15
  • 145
  • 220
Daniel
  • 968
  • 3
  • 13
  • 32
  • Why not *actually* use `window` instead of `this` (which usually only resolves to Window in a global context)? – user2864740 Oct 09 '18 at 16:43
  • @user2864740 As I said, this is not my source. Please ask this question to the Sweetalert2 developers :) – Daniel Oct 09 '18 at 16:45

0 Answers0