@moneko/core 4.3.0-beta.1 → 4.3.1
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/plugin/manifest/index.mjs +1 -1
- package/lib/plugins.config.mjs +1 -1
- package/lib/vm/app.mjs +1 -1
- package/lib/vm/dts.mjs +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as
|
|
1
|
+
import{existsSync as s,readFileSync as t}from"node:fs";import{basename as e,join as i,resolve as o}from"node:path";import a from"webpack";import{isDev as r,packageJson as n}from"../../process-env.mjs";import{app_basic as p}from"../../vm/basic.mjs";export*from"./types.mjs";export class ManifestPlugin{constructor(s){this.name="ManifestPlugin",this.options={filename:"site.webmanifest",name:n.name,description:n.description,scope:"/",display:"standalone",background_color:"#fff",icons:[{src:"https://h5static.dewucdn.com/node-common/718d5e10-576d-8b14-b0b1-e4c58c3b3f40.webp",type:"image/webp",sizes:"512x512"}]},this.options={...this.options,...s}}getPublicPath(s){if(this.options.publicPath)return this.options.publicPath;let t=s.getAssetPath(s.outputOptions.publicPath,{hash:s.hash}),e="auto"===t?"/":t;return e.length&&!e.endsWith("/")&&(e+="/"),e}addAsset(r,n,p){if(!p)return;let c=this.getPublicPath(n);return p.map(p=>{let m={...p};if(m.src&&!m.src.startsWith("http")){let p=o(r.context,m.src);if(s(p)){let s=e(m.src),o=t(p);n.emitAsset(s,new a.sources.RawSource(o),{javascriptModule:!1}),m.src=i(c,s)}else n.warnings.push(new a.WebpackError(`Asset file ${p} does not exist`))}return m})}apply(s){let t=this.name,{filename:e,start_url:i,icons:o,screenshots:c,...m}=this.options;s.hooks.thisCompilation.tap(t,h=>{h.hooks.processAssets.tap({name:t,stage:a.Compilation.PROCESS_ASSETS_STAGE_REPORT},()=>{let t={...m,start_url:i??this.getPublicPath(h),screenshots:this.addAsset(s,h,c),icons:this.addAsset(s,h,o),version:`${n.version}(${r?"Dev":h.fullHash})`};h.emitAsset(e,new s.webpack.sources.RawSource(JSON.stringify(t)),{javascriptModule:!1}),h.emitAsset("app-resource.json",new s.webpack.sources.RawSource(JSON.stringify(h.getAssets().map(s=>s.name))),{javascriptModule:!0}),p.setData("manifest",t),p.setData("resource",h.getAssets().map(s=>s.name))})})}}
|
package/lib/plugins.config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"webpack";import{CompressionPlugin as t}from"./plugin/compression.mjs";import{CopyPlugin as o}from"./plugin/copy.mjs";import{CssModuleDtsPlugin as i}from"./plugin/css-module-dts.mjs";import{HtmlPlugin as r}from"./plugin/html-plugin.mjs";import{ManifestPlugin as
|
|
1
|
+
import e from"webpack";import{CompressionPlugin as t}from"./plugin/compression.mjs";import{CopyPlugin as o}from"./plugin/copy.mjs";import{CssModuleDtsPlugin as i}from"./plugin/css-module-dts.mjs";import{HtmlPlugin as r}from"./plugin/html-plugin.mjs";import{ManifestPlugin as n}from"./plugin/manifest/index.mjs";import p from"./plugin/module-federation.mjs";import{VirtualModulePlugin as s}from"./plugin/virtual-module.mjs";import{app_vm as m}from"./vm/app.mjs";import{docs_vm as l}from"./vm/docs.mjs";import{example_vm as a}from"./vm/example.mjs";import{scope_vm as c}from"./vm/scope.mjs";import{sw_vm as h}from"./vm/sw.mjs";import{virtual_vm as f}from"./vm/virtual.mjs";import{CONFIG as u}from"./config.mjs";import{app_schema as g,docs_schema as d,example_schema as w,isLibrary as j,packageJson as v,scope_schema as b,service_worker_schema as y,virtual_schema as x}from"./process-env.mjs";let P="object"==typeof u.compression?u.compression:{},O=[...p,new s(m,g),new s(h,y),j&&new s(l,d),j&&new s(a,w),j&&new s(c,b),u.virtualModule&&new s(f,x),new o(u.copy),new e.EnviromentPlugin(u.env),new e.DefinePlugin({"process.env":JSON.stringify(u.env)}),new e.IgnorePlugin({resourceRegExp:/\.d\.tsx?$/,contextRegExp:/\/(__(tests|mocks)__|test|spec|e2e)\//}),new i,...u.plugins].filter(Boolean);if(u.compression&&O.push(new t({algorithm:u.devServer.https?"brotli":"gzip",test:/\.(js|css|html|svg|ttf|woff|woff2|png|jpg|jpeg)$/,...P})),u.manifest&&O.push(new n(u.manifest)),u.htmlPluginOption){let e={charset:"UTF-8","X-UA-Compatible":{"http-equiv":"X-UA-Compatible",content:"IE=edge,Chrome=1"},HandheldFriendly:"true",MobileOptimized:"320","screen-orientation":"portrait","x5-orientation":"portrait",browsermode:"application","x5-page-mode":"app","msapplication-tap-highlight":"no","mobile-web-app-capable":"yes",renderer:"webkit",description:v.description,keywords:Array.isArray(v.keywords)?v.keywords.toString():"","http-equiv":"refresh",viewport:"width=device-width, initial-scale=1"};u.seo&&(e.relCanonical={rel:"canonical",href:`https://${u.seo.domain}${u.basename}`}),u.htmlPluginOption.meta&&Object.assign(e,u.htmlPluginOption.meta),O.push(new r({...u.htmlPluginOption,meta:e}))}if(u.fixBrowserRouter){let e=u.basename.split("/").filter(Boolean).length,t=`${Array(e).fill("..").join("/")+(e?"/":"")}404.html`,o=u.fixBrowserRouter.pathSegmentsToKeep??e;O.push(new r({filename:u.fixBrowserRouter.path??t,inject:!1,templateContent:()=>`<html lang="en"><head><title>Redirect</title><script>const pathKeep = ${o};const l = window.location;l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + l.pathname.split('/').slice(0, 1 + pathKeep).join('/') + '/?/' + l.pathname.slice(1).split('/').slice(pathKeep).join('/').replace(/&/g, '~and~') + (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash);</script></head><body></body></html>`}))}u.sourceMap&&O.push(new e.SourceMapDevToolPlugin(u.sourceMap));export default O;
|
package/lib/vm/app.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join as e}from"node:path";import{getAppEntry as r,getAppFallback as o,getAppMergeRouter as t,getAppNormalizeCss as m,getAppPrefixRouter as s,getAppRem as a,getAppSuspense as n}from"@moneko/mdx";import
|
|
1
|
+
import{join as e}from"node:path";import{getAppEntry as r,getAppFallback as o,getAppMergeRouter as t,getAppNormalizeCss as m,getAppPrefixRouter as s,getAppRem as a,getAppSuspense as n}from"@moneko/mdx";import p,{routeDir as i}from"../commom/paths.mjs";import d from"../commom/reactive-object.mjs";import{readJson as f}from"../commom/read-json.mjs";import{CONFIG as l}from"../config.mjs";import c from"../plugin/module-federation.mjs";import{app_schema as u,APPTYPE as y,FRAMEWORK as j,framework as x,frameworkVersionStr as g,SSR as v}from"../process-env.mjs";import b from"../utils/create-types.mjs";import{generateDeclaration as D}from"../utils/dts.mjs";import{convertToCamelCase as C,transformModule as h}from"../utils/index.mjs";import{app_basic as k}from"./basic.mjs";import{vm_dts as E}from"./dts.mjs";import{generateLocales as M}from"./locales.mjs";import $ from"./render-app.mjs";import{getRouter as I}from"./routes.mjs";export const app_vm=new d({env:()=>{let e=`${u}:env`,r=`${h(l.env)}declare global {import AppEnv from '${e}';type ImportMetaEnv = Readonly<typeof AppEnv>;interface ImportMeta {readonly env: ImportMetaEnv;}namespace NodeJS {interface ProcessEnv extends ImportMetaEnv {readonly [key: string]: string | number | boolean | undefined;}}}`;return E.setData(e,b(e,D(r,e))),r},info:r=>{let o=e(p.programPath,"package.json"),t=f(o),m=h({...t,projectName:C(t.name),ssr:v,base:l.basename,type:y,routerMode:l.routerMode,prefixCls:l.prefixCls,theme:l.theme,frameworkVersion:g,framework:x}),s=`${u}:info`;return r?.addDependency(o),E.setData(s,b(s,D(m,s))),m},render:{type:".tsx",source:()=>"react"===j?$:""},entry:()=>r(e(l.alias["@"],"./index.ts"),!!c.length,!!l.rem,!!l.normalizeCss,y,j),fallback:()=>o(l.fallbackCompPath),"merge-router":()=>t(),"prefix-router":()=>s(),suspense:{type:".tsx",source:()=>n(y,j)},routes:e=>(e.addContextDependency(i),I()),locals:r=>{let o=e(l.alias["@"],"./locales");return r.addContextDependency(o),M()},normalize:{type:".css",source:()=>m()},rem:()=>a(l.rem?.designSize||1680),manifest:e=>(e.addContextDependency(l.alias["@"]),`export default ${JSON.stringify(k.getData("manifest"))};`),resource:e=>(e.addContextDependency(l.alias["@"]),`export default ${JSON.stringify(k.getData("resource"))};`)});
|
package/lib/vm/dts.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join as e}from"node:path";import{loadFileSync as t,updateFile as o,updateFileSync as s}from"@moneko/utils";import r from"../commom/paths.mjs";import m from"../commom/reactive-object.mjs";import{readJson as a}from"../commom/read-json.mjs";import{app_schema as n,APPTYPE as i,CACHE_NAME as p,FRAMEWORK as d,framework as c,frameworkVersionStr as
|
|
1
|
+
import{join as e}from"node:path";import{loadFileSync as t,updateFile as o,updateFileSync as s}from"@moneko/utils";import r from"../commom/paths.mjs";import m from"../commom/reactive-object.mjs";import{readJson as a}from"../commom/read-json.mjs";import{app_schema as n,APPTYPE as i,CACHE_NAME as p,FRAMEWORK as d,framework as c,frameworkVersionStr as l,packageJson as f,service_worker_schema as v,SSR as u,virtual_schema as $}from"../process-env.mjs";import j from"../utils/create-types.mjs";import{generateDeclaration as y}from"../utils/dts.mjs";import{convertToCamelCase as M,transformModule as h}from"../utils/index.mjs";export const dts_path=e(r.nodeModules,"@types",p,"index.d.ts");export const vm_dts=new m({});vm_dts.on("change",()=>{let e=Object.values(vm_dts.data).join("\n");o(dts_path,e)});export function initDts(o){let m=j(`${n}:env`,y(`${h(o.env)}declare global {import AppEnv from '${n}:env';type ImportMetaEnv = Readonly<typeof AppEnv>;interface ImportMeta {readonly env: ImportMetaEnv;}namespace NodeJS {interface ProcessEnv extends ImportMetaEnv {readonly [key: string]: string | number | boolean | undefined;}}}`,`${n}:env`));vm_dts.setData(`${n}:env`,m);let _=j(`${n}:info`,y(h({...a(e(r.programPath,"package.json")),projectName:M(f.name),ssr:u,type:i,frameworkVersion:l,framework:c,base:o.basename,routerMode:o.routerMode,prefixCls:o.prefixCls,theme:o.theme}),`${n}:info`));vm_dts.setData(`${n}:info`,_),vm_dts.setData(`${n}:resource`,j(`${n}:resource`,"const resource: string[];export default resource;")),vm_dts.setData(`${n}:manifest`,j(`${n}:manifest`,'import type { WebManifest } from "@moneko/core";const manifest: WebManifest;export default manifest;')),vm_dts.setData(`${v}:precaching`,j(`${v}:precaching`,t(e(r.corePath,"./service-worker/precaching.js.d.ts"))||"")),o.virtualModule&&Object.keys(o.virtualModule).map(e=>{let t=h(o.virtualModule[e]),s=`${$}:${e}`;vm_dts.setData(s,j(s,y(t,s)))});let b=o.moduleFederation?.flatMap(e=>Array.isArray(e.remotes)?e.remotes.map(e=>e.name):[]).filter(Boolean);s(dts_path,Object.values(vm_dts.data).join("\n")),s(e(r.nodeModules,"@moneko/init.d.json"),JSON.stringify({extends:`@moneko/${d}/base`,compilerOptions:{types:[`@moneko/${d}/env.d.ts`,`@types/${p}/index.d.ts`,...b.map(e=>`@types/${p}/${e}.d.ts`)]}}))}
|