guess-webpack
Version:
Webpack plugins for the Machine Learning-driven bundler
1 lines • 3.5 kB
JavaScript
!function(t,e){for(var n in e)t[n]=e[n]}(exports,function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:r})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n.w={},n(n.s=2)}([function(t,e){function n(t){var e=new Error('Cannot find module "'+t+'".');throw e.code="MODULE_NOT_FOUND",e}n.keys=function(){return[]},n.resolve=n,t.exports=n,n.id=0},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t,e){this._node=t,this._map=e}return Object.defineProperty(t.prototype,"probability",{get:function(){return this._node[0]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"route",{get:function(){return this._map.routes[this._node[1]]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"chunk",{get:function(){return this._map.chunks[this._node[2]]},enumerable:!0,configurable:!0}),t}(),o=function(){function t(t,e){this._graph=t,this._map=e}return t.prototype.findMatch=function(t){var e=this,n=this._graph.filter(function(n,r){return i(e._map.routes[r],t)}).pop();return n?n.map(function(t){return new r(t,e._map)}):[]},t}(),i=function(t,e){var n=t.split("/"),r=e.split("/");return n.length>0&&""===n[n.length-1]&&n.pop(),r.length>0&&""===r[r.length-1]&&r.pop(),n.length===r.length&&r.reduce(function(t,e,r){return e.startsWith(":")?t:t&&e===n[r]},!0)};e.guess=function(t){throw new Error("Guess is not initialized")};e.initialize=function(t,n,r,i){var u=new o(n,r);t.__GUESS__=t.__GUESS__||{},t.__GUESS__.guess=e.guess=function(e){return(e=e||{}).path||(e.path=(t.location||{pathname:""}).pathname),e.connection||(e.connection=function(t){return t.navigator&&t.navigator&&t.navigator.connection&&t.navigator.connection.effectiveType||"3g"}(t)),e.thresholds||(e.thresholds=i),function(t,e){return t.findMatch(e.path).reduce(function(t,n){if(n.probability>=e.thresholds[e.connection]){var r={probability:n.probability};n.chunk&&(r.chunk=n.chunk),t[n.route]=r}return t},{})}(u,e)}}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(1),o=function(t,e){var n=r.guess({path:e});Object.keys(n).forEach(function(e){var r=n[e].chunk;r&&c(t,r)})},i=function(t){if("undefined"==typeof document)return!1;var e=document.createElement("link");try{if(e.relList&&"function"==typeof e.relList.supports)return e.relList.supports(t)}catch(t){return!1}}("prefetch")?function(t){if("undefined"!=typeof document){var e=document.createElement("link");e.setAttribute("rel","prefetch"),e.setAttribute("href",t),(document.getElementsByTagName("head")[0]||document.getElementsByName("script")[0].parentNode).appendChild(e)}}:function(t){return Promise.resolve().then(function(){return n(0)(t)})},u={},c=function(t,e){u[e=t+e]||(u[e]=!0,i(e))};e.initialize=function(t,e,n,i,u,c){r.initialize(e,n,i,c),"function"==typeof e.addEventListener&&e.addEventListener("popstate",function(t){return o(u,location.pathname)});var a=t.pushState;t.pushState=function(e){return"function"==typeof t.onpushstate&&t.onpushstate({state:e}),o(u,arguments[2]),a.apply(t,arguments)},o(u,location.pathname)}}]));