@moneko/core 4.8.6-beta.11 → 4.8.6-beta.13

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.
package/lib/config.mjs CHANGED
@@ -1 +1 @@
1
- import{sep as e}from"node:path";import o from"node:process";import{merge as t}from"webpack-merge";import{CUSTOMCONFIG as n}from"./commom/custom-config.mjs";import s from"./commom/paths.mjs";import{join as a}from"./commom/posix.mjs";import i from"./commom/setup-env.mjs";import r from"./options/jsx-dom-expressions.mjs";import m from"./options/split-chunk.mjs";import{getConfigWithTypescript as l,isFunction as p,node_modules as c,resolveProgram as u}from"./utils/index.mjs";import{initDts as d}from"./vm/dts.mjs";import{APPTYPE as f,FRAMEWORK as h,frameworkVersion as g,isCI as v,isDev as x,isLibrary as b,isMobile as j,isReact as C,jsxImportSource as P,mainDirectory as k,NODE_ENV as w,PACKAGENAME as O}from"./process-env.mjs";let I=[/(app|vm|docs|example):[a-zA-Z_0-9]/,"@moneko","neko-ui",".cache/http/data","@element-plus","ant-design-vue","element-plus","element-ui","ng-zorro-antd","@mui","@du","@fontsource","@fortawesome","font-pingfang-sc","font-pingfang-tc","katex","react-markdown-editor-lite","react-photo-view","schema-design","monaco-editor"];export async function getConfig(e){let t=l(e).default;return(p(t)?await t(o):t)??{}}let S=await i(w,f,h,[],"true"===o.env.IS_BUILD,n),[y,M]=await Promise.all([getConfig(s.configPath),getConfig(s.customConfigPath)]),z={mode:w,strict:!1,devtool:"true"!==o.env.IS_BUILD&&x?"eval-cheap-module-source-map":"cheap-module-source-map",seo:!1,bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:!!v&&{},sourceMap:{filename:"[file].map",publicPath:"",namespace:O,moduleFilenameTemplate:"moneko://[namespace]/[resource-path]?[loaders]",fallbackModuleFilenameTemplate:"moneko://[namespace]/[resource-path]?[loaders]"},env:S,basename:"/",publicPath:"auto",rem:{designSize:j?375:1920},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":u(k)},C&&g<18?{"react/package.json":c("react/package.json"),"react/jsx-runtime":c("react/jsx-runtime.js"),"react/jsx-dev-runtime":c("react/jsx-dev-runtime.js")}:{}),moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},devServer:{host:"localhost",port:3e3,open:!0},htmlPluginOption:{title:O.toLocaleUpperCase(),favicon:"https://h5static.dewucdn.com/node-common/718d5e10-576d-8b14-b0b1-e4c58c3b3f40.webp"},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:m,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:I,js:I,media:I,font:I,wasm:[]},mdx:{jsx:!1,development:x,jsxImportSource:P,providerImportSource:`@moneko/${h}/mdx`},jsxDomExpressions:r,bar:{name:"Client",nameColor:"68",msgColor:"242",barBgColor:"15",barColor:"69",quiet:v},normalizeCss:!0,externalsPresets:{},buildHttp:void 0,virtualModule:{},cssExtract:{},externals:["@swc/core"],lazyCompilation:!1,performance:!1,refresh:"solid"!==h,bundleId:"com.moneko.bid",bundles:[],stylelint:{},eslint:{lintDirtyModulesOnly:!1},minChunkSize:1e3,compression:!1,manifest:{filename:"site.webmanifest"},corepack:!0,reactJsxRuntime:"automatic"};b&&(z.alias=Object.assign(z.alias,{"@pkg":s.componentsPath,[O]:s.componentsPath}));let D=z;if((!1===(D=t(D,y,M)).devtool||!1===D.sourceMap)&&(D.sourceMap=!1,D.devtool=!1),"true"===o.env.CODESPACES&&(D.devServer.https=!1),!1===D.devServer.https&&"darwin"===o.platform&&(D.devServer.open=!1),D.htmlPluginOption&&(D.htmlPluginOption.tags||(D.htmlPluginOption.tags=[]),D.fixBrowserRouter&&D.htmlPluginOption.tags.push({textContent:"(function(l) {if (l.search[1] === '/' ) {var decoded = l.search.slice(1).split('&').map(function(s) {return s.replace(/~and~/g, '&')}).join('?');window.history.replaceState(null, null,l.pathname.slice(0, -1) + decoded + l.hash);}}(window.location))"}),D.manifest)){let o=D.manifest.publicPath??D.htmlPluginOption.publicPath??D.publicPath??"/";D.htmlPluginOption.tags.push({href:a("auto"===o?"/":o,D.manifest.filename).replaceAll(e,"/"),tag:"link",rel:"manifest"})}export const CONFIG=D;export const PUBLICPATH="auto"===CONFIG.publicPath?"":CONFIG.publicPath;d(CONFIG);
1
+ import{sep as e}from"node:path";import o from"node:process";import{merge as t}from"webpack-merge";import{CUSTOMCONFIG as n}from"./commom/custom-config.mjs";import s from"./commom/paths.mjs";import{join as a}from"./commom/posix.mjs";import i from"./commom/setup-env.mjs";import r from"./options/jsx-dom-expressions.mjs";import m from"./options/split-chunk.mjs";import{getConfigWithTypescript as l,isFunction as p,node_modules as c,resolveProgram as u}from"./utils/index.mjs";import{initDts as d}from"./vm/dts.mjs";import{APPTYPE as f,FRAMEWORK as h,frameworkVersion as g,isCI as v,isDev as x,isLibrary as b,isMobile as j,isReact as C,jsxImportSource as P,mainDirectory as k,NODE_ENV as w,PACKAGENAME as O}from"./process-env.mjs";let I=[/(app|vm|docs|example):[a-zA-Z_0-9]/,"@moneko","neko-ui",".cache/http/data","@element-plus","ant-design-vue","element-plus","element-ui","ng-zorro-antd","@mui","@du","@fontsource","@fortawesome","font-pingfang-sc","font-pingfang-tc","katex","react-markdown-editor-lite","react-photo-view","schema-design","monaco-editor"];export async function getConfig(e){let t=l(e).default;return(p(t)?await t(o):t)??{}}let S=await i(w,f,h,[],"true"===o.env.IS_BUILD,n),[y,M]=await Promise.all([getConfig(s.configPath),getConfig(s.customConfigPath)]),z={mode:w,strict:!1,devtool:"true"!==o.env.IS_BUILD&&x?"eval-cheap-module-source-map":"cheap-module-source-map",seo:!1,bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:(!!v||!x)&&{},sourceMap:{filename:"[file].map",publicPath:"",namespace:O,moduleFilenameTemplate:"moneko://[namespace]/[resource-path]?[loaders]",fallbackModuleFilenameTemplate:"moneko://[namespace]/[resource-path]?[loaders]"},env:S,basename:"/",publicPath:"auto",rem:{designSize:j?375:1920},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":u(k)},C&&g<18?{"react/package.json":c("react/package.json"),"react/jsx-runtime":c("react/jsx-runtime.js"),"react/jsx-dev-runtime":c("react/jsx-dev-runtime.js")}:{}),moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},devServer:{host:"localhost",port:3e3,open:!0},htmlPluginOption:{title:O.toLocaleUpperCase(),favicon:"https://h5static.dewucdn.com/node-common/718d5e10-576d-8b14-b0b1-e4c58c3b3f40.webp"},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:m,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:I,js:I,media:I,font:I,wasm:[]},mdx:{jsx:!1,development:x,jsxImportSource:P,providerImportSource:`@moneko/${h}/mdx`},jsxDomExpressions:r,bar:{name:"Client",nameColor:"68",msgColor:"242",barBgColor:"15",barColor:"69",quiet:v},normalizeCss:!0,externalsPresets:{},buildHttp:void 0,virtualModule:{},cssExtract:{},externals:["@swc/core"],lazyCompilation:!1,performance:!1,refresh:"solid"!==h,bundleId:"com.moneko.bid",bundles:[],stylelint:{},eslint:{lintDirtyModulesOnly:!1},minChunkSize:1e3,compression:!1,manifest:{filename:"site.webmanifest"},corepack:!0,reactJsxRuntime:"automatic"};b&&(z.alias=Object.assign(z.alias,{"@pkg":s.componentsPath,[O]:s.componentsPath}));let D=z;if((!1===(D=t(D,y,M)).devtool||!1===D.sourceMap)&&(D.sourceMap=!1,D.devtool=!1),"true"===o.env.CODESPACES&&(D.devServer.https=!1),!1===D.devServer.https&&"darwin"===o.platform&&(D.devServer.open=!1),D.htmlPluginOption&&(D.htmlPluginOption.tags||(D.htmlPluginOption.tags=[]),D.fixBrowserRouter&&D.htmlPluginOption.tags.push({textContent:"(function(l) {if (l.search[1] === '/' ) {var decoded = l.search.slice(1).split('&').map(function(s) {return s.replace(/~and~/g, '&')}).join('?');window.history.replaceState(null, null,l.pathname.slice(0, -1) + decoded + l.hash);}}(window.location))"}),D.manifest)){let o=D.manifest.publicPath??D.htmlPluginOption.publicPath??D.publicPath??"/";D.htmlPluginOption.tags.push({href:a("auto"===o?"/":o,D.manifest.filename).replaceAll(e,"/"),tag:"link",rel:"manifest"})}export const CONFIG=D;export const PUBLICPATH="auto"===CONFIG.publicPath?"":CONFIG.publicPath;d(CONFIG);
@@ -1,4 +1,4 @@
1
- import type { createReadStream, existsSync } from 'node:fs';
1
+ import type { createReadStream, existsSync, statSync } from 'node:fs';
2
2
  import { type IncomingMessage, type Server as HttpServer, type ServerResponse } from 'node:http';
3
3
  import { type Server as HttpsServer } from 'node:https';
4
4
  import type { OutputFileSystem } from 'webpack';
@@ -6,6 +6,7 @@ import { type CertOption } from '../dev/get-cert.mjs';
6
6
  export type FileSystem = OutputFileSystem & {
7
7
  existsSync: typeof existsSync;
8
8
  createReadStream: typeof createReadStream;
9
+ statSync: typeof statSync;
9
10
  };
10
11
  type HttpServerResponse = ServerResponse<IncomingMessage> & {
11
12
  req: IncomingMessage;
@@ -1 +1 @@
1
- import{createServer as e}from"node:http";import{createServer as t}from"node:https";import{platform as o}from"node:os";import{extname as r,join as n,sep as i}from"node:path";import{env as s}from"node:process";import{ink as a,println as m}from"@moneko/utils";import{CA_ORGANIZATION as l,isCertificateInstalled as p}from"../commom/ca.mjs";import c from"../commom/mime.mjs";import d from"../commom/open.mjs";import{CONFIG as C}from"../config.mjs";import f from"../dev/get-cert.mjs";import{setupProxy as h}from"../dev/proxy.mjs";import u,{cacheBody as A}from"./mock.mjs";let E={"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Headers":"Authorization, Content-Type, Accept, X-Requested-With, Origin, DNT, User-Agent, Cache-Control, X-CSRF-Token, X-API-Key, X-Client-Version, X-Device-ID, Content-Language, Accept-Language, X-Custom-Header, X-Mx-ReqToken, Keep-Alive, If-Modified-Since","Access-Control-Allow-Methods":"GET, DELETE, HEAD, OPTIONS, POST, PUT, PATCH, PURGE, LINK, UNLINK, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, REPORT, SEARCH, CONNECT, TRACE","Access-Control-Allow-Origin":"*","Cache-Control":"no-store, no-cache, must-revalidate, proxy-revalidate",Pragma:"no-cache",Expires:"0"};async function y(y){let T=n(y.root_dir,"index.html"),g=u();function w(e,t,o){let n=e.headers["accept-encoding"],i=n?.includes("br"),s=`${o}.${i?"br":"gz"}`,a=y.fileSystem.existsSync(s);a&&t.setHeader("Content-Encoding",i?"br":"gzip");let m=y.fileSystem.createReadStream(a?s:o,{autoClose:!0});m.on("open",()=>{t.writeHead(200,Object.assign({},E,y.headers,{"Access-Control-Allow-Origin":e.headers.origin??"*","Content-Type":c[r(o)]||"application/octet-stream"}))}),m.on("error",e=>{switch(m.readable=!0,e.code){case"ENOENT":t.writeHead(301,{Location:"/index.html"}),t.end();break;case"EACCES":t.writeHead(403,{"Content-Type":"text/plain"}),t.end(`Forbidden: ${e.message}`);break;default:t.writeHead(500,{"Content-Type":"text/plain"}),t.end(`Internal Server Error: ${e.message}`)}}),m.pipe(t)}async function O(e,t){if(A(e),!(y.onRequest&&y.onRequest(e,t))){if(!(C.proxy&&await h(e,t,C.proxy)||t.writableEnded||g&&g(e,t))&&!t.writableEnded){if("GET"===e.method){let o=("/"===e.url?T:decodeURIComponent(n(y.root_dir,e.url.replace(y.basename??"/","/")))).split("?")[0];if(y.fileSystem.existsSync(o))return w(e,t,o)}if(e.headers.accept?.includes("text/html"))return w(e,t,T.split("?")[0]);t.writeHead(404,{"Content-Type":"text/plain"}),t.end("File Not Found")}}}let x=y.https?t(await f(y.host,!0===y.https?{install:!0}:y.https),O):e(O);if(x.listen(y.port),y.https&&!await p(l)&&"darwin"===o()){let e=s.npm_execpath?.split(i).pop()?.split(".").shift()||"npm",t=s.npm_lifecycle_event??"start",o=`> sudo ${e} ${t}`;m(a("⚠️ 未检测到本地 SSL 证书,请通过以下命令重启项目以安装证书: ","yellow")),m(a(o,"yellow")),m("")}return y.open&&d(`${y.https?"https:":"http:"}//${y.host}:${y.port}${"/"===y.basename?"":y.basename}`),x}export default y;
1
+ import{createServer as e}from"node:http";import{createServer as t}from"node:https";import{platform as o}from"node:os";import{extname as r,join as n,sep as i}from"node:path";import{env as s}from"node:process";import{ink as a,println as l}from"@moneko/utils";import{CA_ORGANIZATION as m,isCertificateInstalled as p}from"../commom/ca.mjs";import c from"../commom/mime.mjs";import d from"../commom/open.mjs";import{CONFIG as f}from"../config.mjs";import C from"../dev/get-cert.mjs";import{setupProxy as h}from"../dev/proxy.mjs";import u,{cacheBody as y}from"./mock.mjs";let A={"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Headers":"Authorization, Content-Type, Accept, X-Requested-With, Origin, DNT, User-Agent, Cache-Control, X-CSRF-Token, X-API-Key, X-Client-Version, X-Device-ID, Content-Language, Accept-Language, X-Custom-Header, X-Mx-ReqToken, Keep-Alive, If-Modified-Since","Access-Control-Allow-Methods":"GET, DELETE, HEAD, OPTIONS, POST, PUT, PATCH, PURGE, LINK, UNLINK, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, REPORT, SEARCH, CONNECT, TRACE","Access-Control-Allow-Origin":"*","Cache-Control":"no-store, no-cache, must-revalidate, proxy-revalidate",Pragma:"no-cache",Expires:"0"};async function E(E){let S=n(E.root_dir,"index.html"),T=u();function g(e,t,o){let n=e.headers["accept-encoding"],i=n?.includes("br"),s=`${o}.${i?"br":"gz"}`,a=E.fileSystem.existsSync(s);a&&t.setHeader("Content-Encoding",i?"br":"gzip");let l=E.fileSystem.createReadStream(a?s:o,{autoClose:!0});l.on("open",()=>{t.writeHead(200,Object.assign({},A,E.headers,{"Access-Control-Allow-Origin":e.headers.origin??"*","Content-Type":c[r(o)]||"application/octet-stream"}))}),l.on("error",e=>{switch(l.readable=!0,e.code){case"ENOENT":t.writeHead(301,{Location:"/index.html"}),t.end();break;case"EACCES":t.writeHead(403,{"Content-Type":"text/plain"}),t.end(`Forbidden: ${e.message}`);break;default:t.writeHead(500,{"Content-Type":"text/plain"}),t.end(`Internal Server Error: ${e.message}`)}}),l.pipe(t)}async function w(e,t){if(y(e),!(E.onRequest&&E.onRequest(e,t))){if(!(f.proxy&&await h(e,t,f.proxy)||t.writableEnded||T&&T(e,t))&&!t.writableEnded){if("GET"===e.method){let o=("/"===e.url?S:decodeURIComponent(n(E.root_dir,e.url.replace(E.basename??"/","/")))).split("?")[0];if(E.fileSystem.existsSync(o))if(!E.fileSystem.statSync(o).isDirectory())return g(e,t,o);else{let r=n(o,"index.html");if(E.fileSystem.existsSync(r))return g(e,t,r)}}if(e.headers.accept?.includes("text/html"))return g(e,t,S.split("?")[0]);t.writeHead(404,{"Content-Type":"text/plain"}),t.end("File Not Found")}}}let x=E.https?t(await C(E.host,!0===E.https?{install:!0}:E.https),w):e(w);if(x.listen(E.port),E.https&&!await p(m)&&"darwin"===o()){let e=s.npm_execpath?.split(i).pop()?.split(".").shift()||"npm",t=s.npm_lifecycle_event??"start",o=`> sudo ${e} ${t}`;l(a("⚠️ 未检测到本地 SSL 证书,请通过以下命令重启项目以安装证书: ","yellow")),l(a(o,"yellow")),l("")}return E.open&&d(`${E.https?"https:":"http:"}//${E.host}:${E.port}${"/"===E.basename?"":E.basename}`),x}export default E;
@@ -1 +1 @@
1
- import{existsSync as t,readFileSync as e}from"node:fs";import{basename as s,resolve as i,sep as o}from"node:path";import n from"webpack";import{isNetworkUrl as a,join as h}from"../commom/posix.mjs";export class HtmlPlugin{constructor(t={}){this.AddEntry=/(?:.*\/)?main\.[a-zA-Z0-9]+\.entry\.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(l){l.hooks.compilation.tap(this.name,r=>{r.hooks.processAssets.tap({name:this.name,stage:n.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL},()=>{let c;if(this.options.favicon)if(a(this.options.favicon))this.faviconPath=this.options.favicon;else{let a=i(l.context,this.options.favicon);if(t(a)){let t=s(this.options.favicon),i=e(a);r.emitAsset(t,new n.sources.RawSource(i),{javascriptModule:!1});let l=this.getPublicPath(r);this.faviconPath=h(l,t).replaceAll(o,"/")}else r.warnings.push(new n.WebpackError(`Favicon file ${a} does not exist`))}if(c=this.options.templateContent?this.options.templateContent(this.options):this.options.template?e(i(l.context,this.options.template),{encoding:"utf-8"}):this.generateDefaultTemplate(),this.options.inject){let t=this.getAssets(r);c=this.injectAssets(c,t,this.options.inject)}let p="function"==typeof this.options.filename?this.options.filename("index"):this.options.filename||"index.html";r.emitAsset(p,new n.sources.RawSource(c),{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:o="",inject:n=this.options.inject,...a}=t,h=Object.entries(a).filter(([,t])=>null!=t).map(([t,e])=>!0===e?t:`${t}="${e}"`).join(" "),l=`<${i} ${h}>${o}</${i}>`;"head"===n?e.push(l):s.push(l)}),t.head=e.join(""),t.body=s.join(""),this.cachedCustomTags=t,t}getAssets(t){let e={js:[],css:[]},s=["import-scripts","require","async-node"],i=this.getPublicPath(t);for(let n of t.entrypoints.values())for(let t of n.chunks){let n=t.getEntryOptions(),a=n?.chunkLoading;if(!(n?.asyncChunks||a&&s.includes(a)))for(let s of t.files)s.endsWith(".js")?e.js.push(h(i,s).replaceAll(o,"/")):s.endsWith(".css")&&e.css.push(h(i,s).replaceAll(o,"/"))}return e}injectAssets(t,e,s){let i=e.css.length?e.css.map(t=>`<link href="${t}" rel="stylesheet" />`).join(""):"",o=e.js.length?e.js.map(t=>`<script defer ${this.AddEntry.test(t)?'entry="true" ':""}src="${t}"></script>`).join(""):"",n=this.generateCustomTags(),a=t.split("</head>");if(2===a.length){let[t,e]=a,h=e.split("</body>");return"head"===s?`${t}${i}${o}${n.head}</head>${h[0]}${n.body}</body>${h[1]||""}`:`${t}${n.head}</head>${h[0]}${i}${o}${n.body}</body>${h[1]||""}`}return t}}
1
+ import{existsSync as t,readFileSync as e}from"node:fs";import{basename as s,resolve as i,sep as o}from"node:path";import n from"webpack";import{isNetworkUrl as a,join as h}from"../commom/posix.mjs";export class HtmlPlugin{constructor(t={}){this.AddEntry=/(?:.*\/)?main\.[a-zA-Z0-9]+\.entry\.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(l){l.hooks.compilation.tap(this.name,r=>{r.hooks.processAssets.tap({name:this.name,stage:n.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL},()=>{let c;if(this.options.favicon)if(a(this.options.favicon))this.faviconPath=this.options.favicon;else{let a=i(l.context,this.options.favicon);if(t(a)){let t=s(this.options.favicon),i=e(a);r.emitAsset(t,new n.sources.RawSource(i),{javascriptModule:!1});let l=this.getPublicPath(r);this.faviconPath=h(l,t).replaceAll(o,"/")}else r.warnings.push(new n.WebpackError(`Favicon file ${a} does not exist`))}if(c=this.options.templateContent?this.options.templateContent(this.options):this.options.template?e(i(l.context,this.options.template),{encoding:"utf-8"}):this.generateDefaultTemplate(),this.options.inject){let t=this.getAssets(r);c=this.injectAssets(c,t,this.options.inject)}let p="function"==typeof this.options.filename?this.options.filename("index"):this.options.filename||"index.html";r.emitAsset(p,new n.sources.RawSource(c),{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:o="",inject:n=this.options.inject,...a}=t,h=Object.entries(a).filter(([,t])=>null!=t).map(([t,e])=>!0===e?t:`${t}="${e}"`).join(" "),l=`<${i} ${h}>${o}</${i}>`;"head"===n?e.push(l):s.push(l)}),t.head=e.join(""),t.body=s.join(""),this.cachedCustomTags=t,t}getAssets(t){let e={js:[],css:[]},s=["import-scripts","require","async-node"],i=this.getPublicPath(t);for(let n of t.entrypoints.values())for(let t of n.chunks){let n=t.getEntryOptions(),a=n?.chunkLoading;if(!(n?.asyncChunks||a&&s.includes(a)))for(let s of t.files)s.endsWith(".js")?e.js.push(h(i,s).replaceAll(o,"/")):s.endsWith(".css")&&e.css.push(h(i,s).replaceAll(o,"/"))}return e}injectAssets(t,e,s){let i=e.css.length?e.css.map(t=>`<link href="${t}" rel="stylesheet" />`).join(""):"",o=e.js.length?e.js.map(t=>`<script defer ${this.AddEntry.test(t)?'entry="true" ':""}src="${t}"></script>`).join(""):"",n=this.generateCustomTags(),a=t.split("</head>");if(2===a.length){let[t,e]=a,h=e.split("</body>");return"head"===s?`${t}${i}${o}${n.head}</head>${h[0]}${n.body}</body>${h[1]||""}`:`${t}${n.head}</head>${h[0]}${i}${o}${n.body}</body>${h[1]||""}`}return t}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "4.8.6-beta.11",
3
+ "version": "4.8.6-beta.13",
4
4
  "description": "@moneko/core",
5
5
  "main": "lib/index.mjs",
6
6
  "type": "module",