UNPKG

guess-webpack

Version:

Webpack plugins for the Machine Learning-driven bundler

1 lines 2.21 kB
!function(t,n){for(var e in n)t[e]=n[e]}(exports,function(t){var n={};function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e.w={},e(e.s=0)}([function(t,n,e){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){function t(t,n){this._node=t,this._map=n}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,n){this._graph=t,this._map=n}return t.prototype.findMatch=function(t){var n=this,e=this._graph.filter(function(e,r){return i(n._map.routes[r],t)}).pop();return e?e.map(function(t){return new r(t,n._map)}):[]},t}(),i=function(t,n){var e=t.split("/"),r=n.split("/");return e.length>0&&""===e[e.length-1]&&e.pop(),r.length>0&&""===r[r.length-1]&&r.pop(),e.length===r.length&&r.reduce(function(t,n,r){return n.startsWith(":")?t:t&&n===e[r]},!0)};n.guess=function(t){throw new Error("Guess is not initialized")};n.initialize=function(t,e,r,i){var u=new o(e,r);t.__GUESS__=t.__GUESS__||{},t.__GUESS__.guess=n.guess=function(n){return(n=n||{}).path||(n.path=(t.location||{pathname:""}).pathname),n.connection||(n.connection=function(t){return t.navigator&&t.navigator&&t.navigator.connection&&t.navigator.connection.effectiveType||"3g"}(t)),n.thresholds||(n.thresholds=i),function(t,n){return t.findMatch(n.path).reduce(function(t,e){if(e.probability>=n.thresholds[n.connection]){var r={probability:e.probability};e.chunk&&(r.chunk=e.chunk),t[e.route]=r}return t},{})}(u,n)}}}]));