-
-
Save dmsnell/df85757f8e7c153a734b4e9ad9d73b9e to your computer and use it in GitHub Desktop.
Comparing CommonJS vs. ES modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function add( a, b ) { return a + b } | |
export function sum( list ) { return list.reduce( add, 0 ) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const values = [ 1, 2, 3, 4, 5 ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******/ (function(modules) { // webpackBootstrap | |
/******/ // The module cache | |
/******/ var installedModules = {}; | |
/******/ | |
/******/ // The require function | |
/******/ function __webpack_require__(moduleId) { | |
/******/ | |
/******/ // Check if module is in cache | |
/******/ if(installedModules[moduleId]) { | |
/******/ return installedModules[moduleId].exports; | |
/******/ } | |
/******/ // Create a new module (and put it into the cache) | |
/******/ var module = installedModules[moduleId] = { | |
/******/ i: moduleId, | |
/******/ l: false, | |
/******/ exports: {} | |
/******/ }; | |
/******/ | |
/******/ // Execute the module function | |
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | |
/******/ | |
/******/ // Flag the module as loaded | |
/******/ module.l = true; | |
/******/ | |
/******/ // Return the exports of the module | |
/******/ return module.exports; | |
/******/ } | |
/******/ | |
/******/ | |
/******/ // expose the modules object (__webpack_modules__) | |
/******/ __webpack_require__.m = modules; | |
/******/ | |
/******/ // expose the module cache | |
/******/ __webpack_require__.c = installedModules; | |
/******/ | |
/******/ // define getter function for harmony exports | |
/******/ __webpack_require__.d = function(exports, name, getter) { | |
/******/ if(!__webpack_require__.o(exports, name)) { | |
/******/ Object.defineProperty(exports, name, { | |
/******/ configurable: false, | |
/******/ enumerable: true, | |
/******/ get: getter | |
/******/ }); | |
/******/ } | |
/******/ }; | |
/******/ | |
/******/ // getDefaultExport function for compatibility with non-harmony modules | |
/******/ __webpack_require__.n = function(module) { | |
/******/ var getter = module && module.__esModule ? | |
/******/ function getDefault() { return module['default']; } : | |
/******/ function getModuleExports() { return module; }; | |
/******/ __webpack_require__.d(getter, 'a', getter); | |
/******/ return getter; | |
/******/ }; | |
/******/ | |
/******/ // Object.prototype.hasOwnProperty.call | |
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | |
/******/ | |
/******/ // __webpack_public_path__ | |
/******/ __webpack_require__.p = ""; | |
/******/ | |
/******/ // Load entry module and return exports | |
/******/ return __webpack_require__(__webpack_require__.s = 0); | |
/******/ }) | |
/************************************************************************/ | |
/******/ ([ | |
/* 0 */ | |
/***/ (function(module, exports, __webpack_require__) { | |
"use strict"; | |
var _a = __webpack_require__(1); | |
var _b = __webpack_require__(2); | |
console.log((0, _a.sum)(_b.values)); | |
/***/ }), | |
/* 1 */ | |
/***/ (function(module, exports, __webpack_require__) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.add = add; | |
exports.sum = sum; | |
exports.mult = mult; | |
exports.product = product; | |
function add(a, b) { | |
return a + b; | |
} | |
function sum(list) { | |
return list.reduce(add, 0); | |
} | |
function mult(a, b) { | |
return a * b; | |
} | |
function product(list) { | |
return list.reduce(product, 1); | |
} | |
/***/ }), | |
/* 2 */ | |
/***/ (function(module, exports, __webpack_require__) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
const values = exports.values = [1, 2, 3, 4, 5]; | |
/***/ }) | |
/******/ ]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******/ (function(modules) { // webpackBootstrap | |
/******/ // The module cache | |
/******/ var installedModules = {}; | |
/******/ | |
/******/ // The require function | |
/******/ function __webpack_require__(moduleId) { | |
/******/ | |
/******/ // Check if module is in cache | |
/******/ if(installedModules[moduleId]) { | |
/******/ return installedModules[moduleId].exports; | |
/******/ } | |
/******/ // Create a new module (and put it into the cache) | |
/******/ var module = installedModules[moduleId] = { | |
/******/ i: moduleId, | |
/******/ l: false, | |
/******/ exports: {} | |
/******/ }; | |
/******/ | |
/******/ // Execute the module function | |
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | |
/******/ | |
/******/ // Flag the module as loaded | |
/******/ module.l = true; | |
/******/ | |
/******/ // Return the exports of the module | |
/******/ return module.exports; | |
/******/ } | |
/******/ | |
/******/ | |
/******/ // expose the modules object (__webpack_modules__) | |
/******/ __webpack_require__.m = modules; | |
/******/ | |
/******/ // expose the module cache | |
/******/ __webpack_require__.c = installedModules; | |
/******/ | |
/******/ // define getter function for harmony exports | |
/******/ __webpack_require__.d = function(exports, name, getter) { | |
/******/ if(!__webpack_require__.o(exports, name)) { | |
/******/ Object.defineProperty(exports, name, { | |
/******/ configurable: false, | |
/******/ enumerable: true, | |
/******/ get: getter | |
/******/ }); | |
/******/ } | |
/******/ }; | |
/******/ | |
/******/ // getDefaultExport function for compatibility with non-harmony modules | |
/******/ __webpack_require__.n = function(module) { | |
/******/ var getter = module && module.__esModule ? | |
/******/ function getDefault() { return module['default']; } : | |
/******/ function getModuleExports() { return module; }; | |
/******/ __webpack_require__.d(getter, 'a', getter); | |
/******/ return getter; | |
/******/ }; | |
/******/ | |
/******/ // Object.prototype.hasOwnProperty.call | |
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | |
/******/ | |
/******/ // __webpack_public_path__ | |
/******/ __webpack_require__.p = ""; | |
/******/ | |
/******/ // Load entry module and return exports | |
/******/ return __webpack_require__(__webpack_require__.s = 0); | |
/******/ }) | |
/************************************************************************/ | |
/******/ ([ | |
/* 0 */ | |
/***/ (function(module, __webpack_exports__, __webpack_require__) { | |
"use strict"; | |
Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); | |
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__a_js__ = __webpack_require__(1); | |
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__b_js__ = __webpack_require__(2); | |
console.log( Object(__WEBPACK_IMPORTED_MODULE_0__a_js__["a" /* sum */])( __WEBPACK_IMPORTED_MODULE_1__b_js__["a" /* values */] ) ) | |
/***/ }), | |
/* 1 */ | |
/***/ (function(module, __webpack_exports__, __webpack_require__) { | |
"use strict"; | |
/* unused harmony export add */ | |
/* harmony export (immutable) */ __webpack_exports__["a"] = sum; | |
/* unused harmony export mult */ | |
/* unused harmony export product */ | |
function add( a, b ) { return a + b } | |
function sum( list ) { return list.reduce( add, 0 ) } | |
function mult( a, b ) { return a * b } | |
function product( list ) { return list.reduce( product, 1 ) } | |
/***/ }), | |
/* 2 */ | |
/***/ (function(module, __webpack_exports__, __webpack_require__) { | |
"use strict"; | |
const values = [ 1, 2, 3, 4, 5 ] | |
/* harmony export (immutable) */ __webpack_exports__["a"] = values; | |
/***/ }) | |
/******/ ]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(c) { | |
function d(f) { | |
if (e[f]) return e[f].exports; | |
var g = (e[f] = { i: f, l: !1, exports: {} }); | |
return c[f].call(g.exports, g, g.exports, d), (g.l = !0), g.exports; | |
} | |
var e = {}; | |
return ( | |
(d.m = c), | |
(d.c = e), | |
(d.d = function(f, g, h) { | |
d.o(f, g) || | |
Object.defineProperty(f, g, { | |
configurable: !1, | |
enumerable: !0, | |
get: h | |
}); | |
}), | |
(d.n = function(f) { | |
var g = | |
f && f.__esModule | |
? function() { | |
return f["default"]; | |
} | |
: function() { | |
return f; | |
}; | |
return d.d(g, "a", g), g; | |
}), | |
(d.o = function(f, g) { | |
return Object.prototype.hasOwnProperty.call(f, g); | |
}), | |
(d.p = ""), | |
d((d.s = 0)) | |
); | |
})([ | |
function(c, d, e) { | |
"use strict"; | |
Object.defineProperty(d, "__esModule", { value: !0 }); | |
var f = e(1), | |
g = e(2); | |
console.log(Object(f.a)(g.a)); | |
}, | |
function(c, d) { | |
"use strict"; | |
function f(j, k) { | |
return j + k; | |
} | |
d.a = function(j) { | |
return j.reduce(f, 0); | |
}; | |
}, | |
function(c, d) { | |
"use strict"; | |
d.a = [1, 2, 3, 4, 5]; | |
} | |
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { sum } from './a.js' | |
import { values } from './b.js' | |
console.log( sum( values ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment