index.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. function webpackBootstrapFunc (modules) {
  2. /******/ // The module cache
  3. /******/ var installedModules = {};
  4. /******/ // The require function
  5. /******/ function __webpack_require__(moduleId) {
  6. /******/ // Check if module is in cache
  7. /******/ if(installedModules[moduleId])
  8. /******/ return installedModules[moduleId].exports;
  9. /******/ // Create a new module (and put it into the cache)
  10. /******/ var module = installedModules[moduleId] = {
  11. /******/ i: moduleId,
  12. /******/ l: false,
  13. /******/ exports: {}
  14. /******/ };
  15. /******/ // Execute the module function
  16. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  17. /******/ // Flag the module as loaded
  18. /******/ module.l = true;
  19. /******/ // Return the exports of the module
  20. /******/ return module.exports;
  21. /******/ }
  22. /******/ // expose the modules object (__webpack_modules__)
  23. /******/ __webpack_require__.m = modules;
  24. /******/ // expose the module cache
  25. /******/ __webpack_require__.c = installedModules;
  26. /******/ // identity function for calling harmony imports with the correct context
  27. /******/ __webpack_require__.i = function(value) { return value; };
  28. /******/ // define getter function for harmony exports
  29. /******/ __webpack_require__.d = function(exports, name, getter) {
  30. /******/ if(!__webpack_require__.o(exports, name)) {
  31. /******/ Object.defineProperty(exports, name, {
  32. /******/ configurable: false,
  33. /******/ enumerable: true,
  34. /******/ get: getter
  35. /******/ });
  36. /******/ }
  37. /******/ };
  38. /******/ // define __esModule on exports
  39. /******/ __webpack_require__.r = function(exports) {
  40. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  41. /******/ };
  42. /******/ // getDefaultExport function for compatibility with non-harmony modules
  43. /******/ __webpack_require__.n = function(module) {
  44. /******/ var getter = module && module.__esModule ?
  45. /******/ function getDefault() { return module['default']; } :
  46. /******/ function getModuleExports() { return module; };
  47. /******/ __webpack_require__.d(getter, 'a', getter);
  48. /******/ return getter;
  49. /******/ };
  50. /******/ // Object.prototype.hasOwnProperty.call
  51. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  52. /******/ // __webpack_public_path__
  53. /******/ __webpack_require__.p = "/";
  54. /******/ // on error function for async loading
  55. /******/ __webpack_require__.oe = function(err) { console.error(err); throw err; };
  56. var f = __webpack_require__(__webpack_require__.s = ENTRY_MODULE)
  57. return f.default || f // try to call default if defined to also support babel esmodule exports
  58. }
  59. var moduleNameReqExp = '[\\.|\\-|\\+|\\w|\/|@]+'
  60. var dependencyRegExp = '\\(\\s*(\/\\*.*?\\*\/)?\\s*.*?(' + moduleNameReqExp + ').*?\\)' // additional chars when output.pathinfo is true
  61. // http://stackoverflow.com/a/2593661/130442
  62. function quoteRegExp (str) {
  63. return (str + '').replace(/[.?*+^$[\]\\(){}|-]/g, '\\$&')
  64. }
  65. function isNumeric(n) {
  66. return !isNaN(1 * n); // 1 * n converts integers, integers as string ("123"), 1e3 and "1e3" to integers and strings to NaN
  67. }
  68. function getModuleDependencies (sources, module, queueName) {
  69. var retval = {}
  70. retval[queueName] = []
  71. var fnString = module.toString()
  72. var wrapperSignature = fnString.match(/^function\s?\w*\(\w+,\s*\w+,\s*(\w+)\)/)
  73. if (!wrapperSignature) return retval
  74. var webpackRequireName = wrapperSignature[1]
  75. // main bundle deps
  76. var re = new RegExp('(\\\\n|\\W)' + quoteRegExp(webpackRequireName) + dependencyRegExp, 'g')
  77. var match
  78. while ((match = re.exec(fnString))) {
  79. if (match[3] === 'dll-reference') continue
  80. retval[queueName].push(match[3])
  81. }
  82. // dll deps
  83. re = new RegExp('\\(' + quoteRegExp(webpackRequireName) + '\\("(dll-reference\\s(' + moduleNameReqExp + '))"\\)\\)' + dependencyRegExp, 'g')
  84. while ((match = re.exec(fnString))) {
  85. if (!sources[match[2]]) {
  86. retval[queueName].push(match[1])
  87. sources[match[2]] = __webpack_require__(match[1]).m
  88. }
  89. retval[match[2]] = retval[match[2]] || []
  90. retval[match[2]].push(match[4])
  91. }
  92. // convert 1e3 back to 1000 - this can be important after uglify-js converted 1000 to 1e3
  93. var keys = Object.keys(retval);
  94. for (var i = 0; i < keys.length; i++) {
  95. for (var j = 0; j < retval[keys[i]].length; j++) {
  96. if (isNumeric(retval[keys[i]][j])) {
  97. retval[keys[i]][j] = 1 * retval[keys[i]][j];
  98. }
  99. }
  100. }
  101. return retval
  102. }
  103. function hasValuesInQueues (queues) {
  104. var keys = Object.keys(queues)
  105. return keys.reduce(function (hasValues, key) {
  106. return hasValues || queues[key].length > 0
  107. }, false)
  108. }
  109. function getRequiredModules (sources, moduleId) {
  110. var modulesQueue = {
  111. main: [moduleId]
  112. }
  113. var requiredModules = {
  114. main: []
  115. }
  116. var seenModules = {
  117. main: {}
  118. }
  119. while (hasValuesInQueues(modulesQueue)) {
  120. var queues = Object.keys(modulesQueue)
  121. for (var i = 0; i < queues.length; i++) {
  122. var queueName = queues[i]
  123. var queue = modulesQueue[queueName]
  124. var moduleToCheck = queue.pop()
  125. seenModules[queueName] = seenModules[queueName] || {}
  126. if (seenModules[queueName][moduleToCheck] || !sources[queueName][moduleToCheck]) continue
  127. seenModules[queueName][moduleToCheck] = true
  128. requiredModules[queueName] = requiredModules[queueName] || []
  129. requiredModules[queueName].push(moduleToCheck)
  130. var newModules = getModuleDependencies(sources, sources[queueName][moduleToCheck], queueName)
  131. var newModulesKeys = Object.keys(newModules)
  132. for (var j = 0; j < newModulesKeys.length; j++) {
  133. modulesQueue[newModulesKeys[j]] = modulesQueue[newModulesKeys[j]] || []
  134. modulesQueue[newModulesKeys[j]] = modulesQueue[newModulesKeys[j]].concat(newModules[newModulesKeys[j]])
  135. }
  136. }
  137. }
  138. return requiredModules
  139. }
  140. module.exports = function (moduleId, options) {
  141. options = options || {}
  142. var sources = {
  143. main: __webpack_modules__
  144. }
  145. var requiredModules = options.all ? { main: Object.keys(sources.main) } : getRequiredModules(sources, moduleId)
  146. var src = ''
  147. Object.keys(requiredModules).filter(function (m) { return m !== 'main' }).forEach(function (module) {
  148. var entryModule = 0
  149. while (requiredModules[module][entryModule]) {
  150. entryModule++
  151. }
  152. requiredModules[module].push(entryModule)
  153. sources[module][entryModule] = '(function(module, exports, __webpack_require__) { module.exports = __webpack_require__; })'
  154. src = src + 'var ' + module + ' = (' + webpackBootstrapFunc.toString().replace('ENTRY_MODULE', JSON.stringify(entryModule)) + ')({' + requiredModules[module].map(function (id) { return '' + JSON.stringify(id) + ': ' + sources[module][id].toString() }).join(',') + '});\n'
  155. })
  156. src = src + 'new ((' + webpackBootstrapFunc.toString().replace('ENTRY_MODULE', JSON.stringify(moduleId)) + ')({' + requiredModules.main.map(function (id) { return '' + JSON.stringify(id) + ': ' + sources.main[id].toString() }).join(',') + '}))(self);'
  157. var blob = new window.Blob([src], { type: 'text/javascript' })
  158. if (options.bare) { return blob }
  159. var URL = window.URL || window.webkitURL || window.mozURL || window.msURL
  160. var workerUrl = URL.createObjectURL(blob)
  161. var worker = new window.Worker(workerUrl)
  162. worker.objectURL = workerUrl
  163. return worker
  164. }