media-query-splitting-plugin
Version:
Webpack 4 plugin for styles splitting by media query
1 lines • 1.98 kB
JavaScript
;function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}var getPrefetchOption=function(a){var b=a.prefetch,c=a.mediaKeys,d=a.mediaKey,e=Array.isArray(b)?b:b?[b]:[],f=e.filter(function(a){return!c.includes(a)});return f.length?(console.error("\n Wrong prefetch values passed to \"prefetch\" parameter: ".concat(f.join(", ")," at media \"").concat(d,"\".\n Allowed values: ").concat(c.join(", "),"\n ")),[]):e},getMediaOptions=function(a){var b={},c=Object.keys(a);return c.forEach(function(d){var e=a[d];if("common"===d)console.error("\n Wrong media key \"common\", this key is used for styles without media query or with unmatched query\n ");else if("string"==typeof e)b[d]={query:e,exact:!1,withCommonStyles:!0};else if("object"===_typeof(e)&&e.query&&"string"==typeof e.query){var f=e.query,g=e.prefetch,h=e.exact,i=e.withCommonStyles;b[d]={query:f,exact:!!(void 0!==h&&h),prefetch:getPrefetchOption({prefetch:g,mediaKeys:c,mediaKey:d}),withCommonStyles:void 0===i||i}}else console.error("\n Wrong mediaQuery value \"".concat(JSON.stringify(e),"\" passed to config for media \"").concat(d,"\",\n allowed types: String or Object with params: query, exact, prefetch\n "))}),b},getOptions=function(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},b=a.minify,c=a.chunkFileName,d=void 0===c?"[id].[contenthash].css":c,e=a.media;return{minify:!(void 0!==b)||b,media:getMediaOptions(e||{mobile:"(max-width: 568px)",tabletPortrait:{query:"(min-width: 569px) and (max-width: 768px)",prefetch:"tabletLandscape",withCommonStyles:!1},tabletLandscape:{query:"(min-width: 769px) and (max-width: 1024px)",prefetch:"tabletPortrait",withCommonStyles:!1},desktop:"(min-width: 1025px)"}),chunkFileName:d}};module.exports=getOptions;