@moneko/core 3.58.1-bate.2 → 3.58.1-bate.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as t,readFileSync as e}from"node:fs";import{basename as s,resolve as
|
|
1
|
+
import{existsSync as t,readFileSync as e}from"node:fs";import{basename as s,join as i,resolve as n}from"node:path";import o from"webpack";export class HtmlPlugin{constructor(t={}){this.AddEntry=/(?:.*\/)?main\.[a-zA-Z0-9]+\.bundle\.js$/,this.faviconPath="",this.name="HtmlPlugin",this.cachedMetaTags=null,this.cachedCustomTags=null,this.options={title:"WebApp",filename:"index.html",inject:"head",...t}}getPublicPath(t){if("string"==typeof this.options.publicPath)return this.options.publicPath;let e=t.getAssetPath(t.outputOptions.publicPath,{hash:t.hash}),s="auto"===e?"/":e;return s.length&&!s.endsWith("/")&&(s+="/"),s}apply(a){a.hooks.compilation.tap(this.name,h=>{h.hooks.processAssets.tap({name:this.name,stage:o.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL},()=>{let r;if(this.options.favicon){let r=n(a.context,this.options.favicon);if(t(r)){let t=s(this.options.favicon),n=e(r);h.emitAsset(t,new o.sources.RawSource(n),{javascriptModule:!1});let a=this.getPublicPath(h);this.faviconPath=i(a,t)}else h.warnings.push(new o.WebpackError(`Favicon file ${r} does not exist`))}if(r=this.options.templateContent?this.options.templateContent(this.options):this.options.template?e(n(a.context,this.options.template),{encoding:"utf-8"}):this.generateDefaultTemplate(),this.options.inject){let t=this.getAssets(h);r=this.injectAssets(r,t,this.options.inject)}let l="function"==typeof this.options.filename?this.options.filename("index"):this.options.filename||"index.html";h.emitAsset(l,new o.sources.RawSource(r),{javascriptModule:!1})})})}generateDefaultTemplate(){let t=this.generateMetaTags();return`<!DOCTYPE html><html><head><meta charset="utf-8">${t}<title>${this.options.title}</title><link rel="icon" type="image/x-icon" href="${this.faviconPath}"></head><body><div id="root"></div></body></html>`}generateMetaTags(){if(null!==this.cachedMetaTags)return this.cachedMetaTags;if(!this.options.meta)return this.cachedMetaTags="","";let t=Object.entries(this.options.meta).map(([t,e])=>{if("string"==typeof e)return`<meta name="${t}" content="${e}">`;if(void 0===e)return"";let s=Object.entries(e).map(([t,e])=>`${t}="${e}"`).join(" ");return`<meta ${s}>`}).join("");return this.cachedMetaTags=t,t}generateCustomTags(){if(null!==this.cachedCustomTags)return this.cachedCustomTags;let t={head:"",body:""};if(!this.options.tags)return this.cachedCustomTags=t,t;let e=[],s=[];return this.options.tags.forEach(t=>{let{tag:i="script",textContent:n="",inject:o=this.options.inject,...a}=t,h=Object.entries(a).filter(([,t])=>null!=t).map(([t,e])=>!0===e?t:`${t}="${e}"`).join(" "),r=`<${i} ${h}>${n}</${i}>`;"head"===o?e.push(r):s.push(r)}),t.head=e.join(""),t.body=s.join(""),this.cachedCustomTags=t,t}getAssets(t){let e={js:[],css:[]},s=["import-scripts","require","async-node"],n=this.getPublicPath(t);for(let o of t.entrypoints.values())for(let t of o.chunks){let o=t.getEntryOptions(),a=o?.chunkLoading;if(!(o?.asyncChunks||a&&s.includes(a)))for(let s of t.files)s.endsWith(".js")?e.js.push(i(n,s)):s.endsWith(".css")&&e.css.push(i(n,s))}return e}injectAssets(t,e,s){let i=e.css.length?e.css.map(t=>`<link href="${t}" rel="stylesheet" />`).join(""):"",n=e.js.length?e.js.map(t=>`<script defer ${this.AddEntry.test(t)?'entry="true" ':""}src="${t}"></script>`).join(""):"",o=this.generateCustomTags(),a=t.split("</head>");if(2===a.length){let[t,e]=a,h=e.split("</body>");return"head"===s?`${t}${i}${n}${o.head}</head>${h[0]}${o.body}</body>${h[1]||""}`:`${t}${o.head}</head>${h[0]}${i}${n}${o.body}</body>${h[1]||""}`}return t}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as t,readFileSync as s}from"node:fs";import{basename as o,
|
|
1
|
+
import{existsSync as t,readFileSync as s}from"node:fs";import{basename as o,join as e,relative as i,resolve as r}from"node:path";import a from"webpack";import n from"../../commom/paths.mjs";import{packageJson as p}from"../../process-env.mjs";export*from"./types.mjs";export class ManifestPlugin{constructor(t){this.name="ManifestPlugin",this.options={filename:"site.webmanifest",name:p.name,short_name:p.shortName,description:p.description,scope:"/",display:p.display??"standalone",background_color:p.backgroundColor??"#fff",theme_color:p.themeColor,icons:[{src:i(n.programPath,`${n.corePath}/options/icon.webp`),type:"image/webp",sizes:"512x512"}]},this.options={...this.options,...t}}getPublicPath(t){if(this.options.publicPath)return this.options.publicPath;let s=t.getAssetPath(t.outputOptions.publicPath,{hash:t.hash}),o="auto"===s?"/":s;return o.length&&!o.endsWith("/")&&(o+="/"),o}apply(i){let n=this.name,{filename:c,publicPath:h,start_url:m,...l}=this.options;i.hooks.compilation.tap(n,u=>{u.hooks.processAssets.tap({name:n,stage:a.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL},()=>{let n=h||this.getPublicPath(u),f={...l,start_url:m??n,icons:l.icons?.map(p=>{let c={...p};if(c.src&&!c.src.startsWith("http")){let p=r(i.context,c.src);if(t(p)){let t=o(c.src),i=s(p);u.emitAsset(t,new a.sources.RawSource(i),{javascriptModule:!1}),c.src=e(n,t)}else u.warnings.push(new a.WebpackError(`Icon file ${p} does not exist`))}return c}),version:`${p.version}(${u.fullHash})`};u.emitAsset(c,new i.webpack.sources.RawSource(JSON.stringify(f)),{javascriptModule:!1})})})}}
|