sw-builder
Version:
The sw-builder package automates the creation of your Application's Service Worker, which pre-caches your build. This leads to a better overall performance and enables users to access your PWA without an Internet connection.
1 lines • 985 B
JavaScript
import{encodeError}from"error-message-utils";import{ERRORS}from"../shared/errors.js";import{BASE_TEMPLATE}from"./templates/base-template.js";const __insertCacheName=(e,r)=>e.replace("const CACHE_NAME = '';",`const CACHE_NAME = '${r}';`),stringifyArrayConstant=(e,r)=>{let t=`const ${e} = [\n`;return t+=r.reduce(((e,t,s)=>`${e} '${t}'${s<r.length-1?",\n":","}`),""),t+="\n];",t},__insertPrecacheAssets=(e,r)=>e.replace("const PRECACHE_ASSETS = [];",stringifyArrayConstant("PRECACHE_ASSETS",r)),__insertExcludeMIMETypes=(e,r)=>e.replace("const EXCLUDE_MIME_TYPES = [];",stringifyArrayConstant("EXCLUDE_MIME_TYPES",r)),__buildBaseTemplate=(e,r,t)=>{let s=__insertCacheName(BASE_TEMPLATE,e);return s=__insertPrecacheAssets(s,r),s=__insertExcludeMIMETypes(s,t),s},buildTemplate=(e,r,t,s)=>{if("base"===e)return __buildBaseTemplate(r,t,s);throw new Error(encodeError(`The template name '${e}' is not supported.`,ERRORS.INVALID_TEMPLATE_NAME))};export{stringifyArrayConstant,buildTemplate};