@moneko/core 3.27.5 → 3.27.6-beta.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/build.mjs +1 -1
- package/lib/common.d.mts +5 -2
- package/lib/common.mjs +1 -1
- package/lib/config.d.mts +3 -2
- package/lib/config.mjs +1 -1
- package/lib/dev.d.mts +0 -2
- package/lib/dev.mjs +1 -1
- package/lib/entry/react.d.mts +13 -0
- package/lib/entry/react.mjs +41 -0
- package/lib/loader/lightning-css/loader.cjs +1 -1
- package/lib/loader/lightning-css/runtime/get-url.cjs +1 -1
- package/lib/loader/lightning-css/runtime/get-url.d.cts +3 -1
- package/lib/module.config.mjs +2 -2
- package/lib/options/modify-vars.d.mts +2 -0
- package/lib/options/modify-vars.mjs +1 -1
- package/lib/options/swcrc.d.mts +7 -0
- package/lib/plugin/html-plugin.mjs +1 -1
- package/lib/plugins.config.mjs +1 -1
- package/lib/process-env.d.mts +3 -0
- package/lib/process-env.mjs +1 -1
- package/lib/vm/docs.d.mts +1 -2
- package/lib/vm/docs.mjs +1 -1
- package/lib/vm/info.d.mts +2 -4
- package/lib/vm/info.mjs +1 -1
- package/lib/vm/modules.d.mts +3 -0
- package/lib/vm/modules.mjs +1 -1
- package/lib/vm/render-app.d.mts +8 -0
- package/lib/vm/render-app.mjs +41 -0
- package/package.json +2 -2
- package/typings/global.d.ts +2 -2
package/lib/build.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{relative as o}from"node:path";import{analyzeBundleSize as
|
|
1
|
+
import{relative as o}from"node:path";import{analyzeBundleSize as r,completedInfo as m,ink as i,println as t,progressBar as e}from"@moneko/utils";import n from"webpack";import{merge as s}from"webpack-merge";import a from"./build/common.mjs";import p from"./commom/paths.mjs";import l from"./plugin/done.mjs";import{empty as u}from"./utils/index.mjs";import c from"./utils/seo.mjs";import{CONFIG as g}from"./config.mjs";import f from"./module.config.mjs";let d=s(a,{module:f(!1),plugins:[]});if(g.done&&d.plugins.push(new l({done:g.done})),g.bar){let o=g.bar,r=o.name||"Build";d.plugins.push(new n.ProgressPlugin({handler(m,i,...t){e(m||0,1,{msg:t.length?`[${i}] ${t.join(" ")}`:"",name:r,barColor:o.barColor,nameColor:o.nameColor,barBgColor:o.barBgColor,msgColor:o.msgColor}),1===m&&process.stdout.write("\r\x1b[2K")}}))}let h=n(d);async function w(){let e=await new Promise((o,r)=>{h.run((m,i)=>{m&&r(m),i?o(i):r(Error("编译过程中没有生成统计信息"))})});(e.hasErrors()||e.hasWarnings())&&function(o){let{warnings:r,errors:m}=o.compilation;r.forEach(o=>{t(i(o.message,"178"))}),m.forEach(o=>{t(i(o.message,"red"))})}(e),await new Promise(n=>{e.compilation.compiler.cache.shutdown(s=>{s&&t(i(s.toString(),"red")),r(e.compilation.outputOptions.path,["\\.js$"]),m(~~((e.endTime-e.startTime)/10)/100,o(p.programPath,e.compilation.outputOptions.path)),n()})}),g.seo&&c()}process.on("exit",u),await w();
|
package/lib/common.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { extname, join, resolve } from 'node:path';
|
|
2
2
|
import type { Configuration, FileCacheOptions } from 'webpack';
|
|
3
3
|
import paths, { config_files, CUSTOMCONFIG } from './commom/paths.mjs';
|
|
4
|
-
import
|
|
4
|
+
import require from './commom/require.mjs';
|
|
5
|
+
import OverrideResolverPlugin, { type OverrideResolverOption } from './plugin/override-resolve.mjs';
|
|
5
6
|
import { isObject, node_modules, resolveProgram } from './utils/index.mjs';
|
|
6
7
|
import { exampleModuleName } from './vm/example.mjs';
|
|
7
8
|
import app from './vm/info.mjs';
|
|
@@ -9,6 +10,8 @@ import { CONFIG, PUBLICPATH } from './config.mjs';
|
|
|
9
10
|
import plugins from './plugins.config.mjs';
|
|
10
11
|
import { isDev, isLibrary, NODE_ENV, PACKAGENAME, PACKAGEVERSION } from './process-env.mjs';
|
|
11
12
|
export declare const outputConfig: Configuration['output'];
|
|
12
|
-
declare let entryMap:
|
|
13
|
+
declare let entryMap: {
|
|
14
|
+
readonly main: string[];
|
|
15
|
+
};
|
|
13
16
|
declare let cacheConfig: FileCacheOptions | false;
|
|
14
17
|
export declare const commonConfig: Configuration;
|
package/lib/common.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extname as e,join as t,resolve as o}from"node:path";import s,{config_files as n,CUSTOMCONFIG as a}from"./commom/paths.mjs";import i from"./plugin/override-resolve.mjs";import{isObject as
|
|
1
|
+
import{extname as e,join as t,resolve as o}from"node:path";import s,{config_files as n,CUSTOMCONFIG as a}from"./commom/paths.mjs";import i from"./commom/require.mjs";import r from"./plugin/override-resolve.mjs";import{isObject as m,node_modules as l,resolveProgram as p}from"./utils/index.mjs";import{exampleModuleName as c}from"./vm/example.mjs";import u from"./vm/info.mjs";import{CONFIG as h,PUBLICPATH as d}from"./config.mjs";import f from"./plugins.config.mjs";import{isDev as g,isLibrary as b,NODE_ENV as j,PACKAGENAME as y,PACKAGEVERSION as v}from"./process-env.mjs";export const outputConfig={path:p(b?"docs":"dist"),filename:"js/[name].bundle.js",chunkFilename:`js/[${g?"name":"contenthash"}].js`,assetModuleFilename:t=>{let o=e(t.filename||"").substring(1);return`assets/${o}/[name][hash][ext]`},library:{name:`${u.projectName}`,type:"umd",umdNamedDefine:!0},globalObject:"window",chunkLoadingGlobal:`webpackJsonp_${y}`,pathinfo:g,clean:!0,publicPath:d,asyncChunks:!0,charset:!0,iife:!0,crossOriginLoading:"anonymous",enabledWasmLoadingTypes:["fetch"],hotUpdateChunkFilename:"[id].[fullhash].hot.js",hotUpdateMainFilename:"[runtime].[fullhash].hot.json"};let C={main:[l("@app/entry")]};h.polyfill&&C.main.unshift(t(s.corePath,"./polyfills/replace-children.mjs")),g&&h.refresh&&h.env.injectRemoteReactRefresh&&C.main.unshift(i.resolve("@moneko/react/lib/injectRemoteReactRefresh.js")),h.entry&&("string"==typeof h.entry?C={main:[h.entry]}:Object.keys(h.entry)&&(C=Object.assign(C,h.entry))),"string"==typeof C.main&&(C.main=[C.main]),h.output&&("string"==typeof h.output?outputConfig.path=h.output:Object.keys(h.output)&&Object.assign(outputConfig,h.output));let k={type:"filesystem",allowCollectingMemory:!0,cacheDirectory:s.webpackCachePath,memoryCacheUnaffected:!0,name:`.${[a,j].filter(Boolean).join("-")}`,version:`${v}`,buildDependencies:{config:n}};!1===h.cache?k=!1:m(h.cache)&&(k=Object.assign(k,h.cache));export const commonConfig={name:"client",target:"web",devtool:h.devtool,entry:C,mode:g?"development":"production",stats:"errors-only",cache:k,snapshot:{immutablePaths:[/node_modules\/(?!(@app|@moneko)\/)/],managedPaths:[/^@app\/.+/,/^@moneko\/.+/],buildDependencies:{timestamp:!0,hash:!0}},infrastructureLogging:{level:"error"},externalsPresets:h.externalsPresets,plugins:f,node:{global:!1,__filename:!1,__dirname:!1},experiments:{topLevelAwait:!0,asyncWebAssembly:!0,cacheUnaffected:!0,layers:!0,lazyCompilation:h.lazyCompilation&&g&&{imports:!0,entries:!0,test:e=>{let t=e.nameForCondition();return!!(t&&(t.startsWith(l(c))||t.startsWith(l("@app/comment"))||t.startsWith(s.pagesPath)||t.startsWith(s.componentsPath)))}},buildHttp:m(h.buildHttp)?{allowedUris:[],lockfileLocation:o(s.httpCachePath,"http.lock"),cacheLocation:o(s.httpCachePath,"data"),upgrade:!0,...h.buildHttp}:h.buildHttp,backCompat:!0,futureDefaults:!0,css:!1,outputModule:!1},resolve:{extensions:[".mts",".mjs",".ts",".tsx",".js",".jsx",".json",".wasm"],alias:h.alias,modules:[s.nodeModules,s.pnpmNodeModules,s.denoNodeModules],mainFields:["browser","module","main"],mainFiles:["index"],plugins:h.resolvePlugins,preferAbsolute:!0,cache:!0,fallback:{}},externals:h.externals,output:outputConfig};h.overrideResolve&&commonConfig.resolve.plugins.push(new r(Object.assign({original:h.alias["@"],override:a&&p(a)},h.overrideResolve)));
|
package/lib/config.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { relative } from 'node:path';
|
|
1
2
|
import { fileExists } from '@moneko/utils';
|
|
2
3
|
import { merge } from 'webpack-merge';
|
|
3
4
|
import paths from './commom/paths.mjs';
|
|
@@ -5,9 +6,9 @@ import require from './commom/require.mjs';
|
|
|
5
6
|
import setupEnv from './commom/setup-env.mjs';
|
|
6
7
|
import jsxDomExpressions from './options/jsx-dom-expressions.mjs';
|
|
7
8
|
import splitChunk from './options/split-chunk.mjs';
|
|
8
|
-
import { isFunction, resolveProgram } from './utils/index.mjs';
|
|
9
|
+
import { isFunction, node_modules, resolveProgram } from './utils/index.mjs';
|
|
9
10
|
import type { ConfigType } from './index.mjs';
|
|
10
|
-
import { APPTYPE,
|
|
11
|
+
import { APPTYPE, FRAMEWORK, frameworkVersion, isDev, isLibrary, isMobile, isReact, jsxImportSource, mainDirectory, NODE_ENV, PACKAGENAME } from './process-env.mjs';
|
|
11
12
|
declare const includeModule: readonly [string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string];
|
|
12
13
|
export declare function getConfig(path: string): Promise<ConfigType>;
|
|
13
14
|
type EnvType = {
|
package/lib/config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{relative as e}from"node:path";import{fileExists as o}from"@moneko/utils";import{merge as t}from"webpack-merge";import n from"./commom/paths.mjs";import r from"./commom/require.mjs";import s from"./commom/setup-env.mjs";import i from"./options/jsx-dom-expressions.mjs";import a from"./options/split-chunk.mjs";import{isFunction as l,node_modules as m,resolveProgram as p}from"./utils/index.mjs";import{APPTYPE as c,FRAMEWORK as u,frameworkVersion as d,isDev as f,isLibrary as g,isMobile as h,isReact as x,jsxImportSource as v,mainDirectory as j,NODE_ENV as P,PACKAGENAME as C}from"./process-env.mjs";let b=["@app","@moneko","neko-ui",".cache/http/data","@ant-design","@antv","@antv/x6","@antv/x6-react-components","@element-plus","ant-design-vue","antd","antd-mini","antd-mobile","antd-mobile-icons","element-plus","element-ui","ng-zorro-antd","@antv","@mui","@du","ahooks","rc-queue-anim","umi","@fontsource","@fortawesome","font-pingfang-sc","font-pingfang-tc","katex","react-markdown-editor-lite","react-photo-view","schema-design"];export function getConfig(e){return delete r.cache[e],new Promise(t=>{if(o(e)){let o=r(e).default;return t(l(o)?o(process):o)}return t({})})}let k=await Promise.all([s(P,c,u,[]),getConfig(n.configPath),getConfig(n.customConfigPath)]),w=k[0],O=k[1],y=k[2],I={devtool:f?"eval-cheap-module-source-map":"cheap-module-source-map",seo:!1,mode:"csr",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{},sourceMap:{filename:"[file].map",publicPath:""},env:w,basename:"/",publicPath:"/",rem:{designSize:h?375:1920},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":p(j)},x&&d<18?{"react/package.json":m("react/package.json"),"react/jsx-runtime":m("react/jsx-runtime.js"),"react/jsx-dev-runtime":m("react/jsx-dev-runtime.js")}:{}),moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},devServer:{host:"localhost",port:3e3},htmlPluginOption:{title:C.toLocaleUpperCase(),favicon:e(n.programPath,`${n.corePath}/options/favicon.ico`)},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:a,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:b,js:b,media:b,font:b,wasm:[]},mdx:{jsx:!1,development:f,jsxImportSource:v,providerImportSource:`@moneko/${u}/mdx`},jsxDomExpressions:i,bar:{name:"Client",nameColor:"68",msgColor:"242",barBgColor:"15",barColor:"69"},normalizeCss:!0,externalsPresets:{},buildHttp:void 0,virtualModule:{},cssExtract:{},externals:["@swc/core"],lazyCompilation:!1,performance:!1,refresh:"solid"!==u,bundleId:"com.moneko.bid",bundles:[],stylelint:!0,eslint:!0};g&&(I.alias=Object.assign(I.alias,{"@pkg":n.componentsPath,[C]:n.componentsPath}));let M=I;(!1===(M=t(M,O,y)).devtool||!1===M.sourceMap)&&(M.sourceMap=!1,M.devtool=!1),M.fixBrowserRouter&&M.htmlPluginOption&&(M.htmlPluginOption.tags||(M.htmlPluginOption.tags=[]),M.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))"}));export const CONFIG=M;export const PUBLICPATH=CONFIG.publicPath;
|
package/lib/dev.d.mts
CHANGED
|
@@ -34,8 +34,6 @@ declare const hmrPath: string;
|
|
|
34
34
|
declare const clientParams: ClientOptions;
|
|
35
35
|
declare const hotParams: string;
|
|
36
36
|
declare const path: string | undefined;
|
|
37
|
-
declare const bar: ConfigType['bar'];
|
|
38
|
-
declare const bar_name: string;
|
|
39
37
|
declare const clientOption: webpack.Configuration;
|
|
40
38
|
declare const compilers: webpack.Compiler;
|
|
41
39
|
interface FastifyOptions {
|
package/lib/dev.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import{relative as r}from"node:path";import
|
|
1
|
+
import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import{relative as r}from"node:path";import i from"@fastify/compress";import{fastifyMiddie as s}from"@fastify/middie";import{ink as l,loadFile as n,print as a,println as m,progressBar as p}from"@moneko/utils";import c from"fastify";import d from"webpack";import u from"webpack-dev-middleware";import h from"webpack-hot-middleware";import{merge as f}from"webpack-merge";import{diffObject as g}from"./commom/diff-object.mjs";import w from"./commom/has-pkg.mjs";import y,{config_files as x}from"./commom/paths.mjs";import v from"./commom/rule.mjs";import C from"./commom/sigint-exit.mjs";import{devLog as k,PORT as $}from"./dev/config.mjs";import b from"./dev/mock.mjs";import{setupProxy as j}from"./dev/proxy.mjs";import P from"./options/reslove.mjs";import S from"./plugin/stylelint.mjs";import{empty as A,resolveProgram as E}from"./utils/index.mjs";import{commonConfig as T}from"./common.mjs";import{CONFIG as I,getConfig as M,PUBLICPATH as _}from"./config.mjs";import R from"./module.config.mjs";import{isLibrary as B,isReact as H,refresh as O}from"./process-env.mjs";let q=I.eslint&&w("eslint-webpack-plugin")&&(await import("eslint-webpack-plugin")).default,z=["js","jsx","ts","tsx","json","html","vue"],U=z.join(","),D=`${_.endsWith("/")?"":"/"}__hmr__`,G=new URLSearchParams({name:"client",path:D,dynamicPublicPath:!0,timeout:2e3,reload:!O,quiet:!0,noInfo:!0,overlay:!0,autoConnect:!0}).toString(),L=T.output.path,W=f(T,{entry:{main:[`${P.hotMiddlewareClient}?${G}`]},output:{path:L},module:R(!1),optimization:{minimize:!1,concatenateModules:!1,removeAvailableModules:!1,removeEmptyChunks:!0,providedExports:!0,usedExports:!1,sideEffects:!1,splitChunks:{chunks:"all",minChunks:1,minSize:30720,maxSize:0,maxAsyncRequests:60,maxInitialRequests:50,hidePathInfo:!1,cacheGroups:{vendors:{test:v.node_modules,priority:-10,reuseExistingChunk:!0},default:{minChunks:1,priority:-20,reuseExistingChunk:!0}}}},plugins:[new d.HotModuleReplacementPlugin,new d.WatchIgnorePlugin({paths:[/node_modules\/(?!(@app|@moneko)).+/,/\.d\.ts$/]})]});if(W.plugins||(W.plugins=[]),H){let e=(await import("@pmmmwh/react-refresh-webpack-plugin")).default;W.plugins.push(new e)}if(q&&W.plugins.push(new q({fix:!0,threads:!0,files:[`${I.alias["@"]}/**/*.{${U}}`,B&&`${I.alias["@pkg"]}/**/*.{${U}}`].filter(Boolean),extensions:z,exclude:["node_modules/","es/","lib/","umd/","docs/","coverage/","dist/"],cache:!0,cacheLocation:`${y.lintCachePath}/.eslintcache`,lintDirtyModulesOnly:!0,overrideConfigFile:E("eslint.config.mjs"),configType:"flat"})),I.stylelint){let e="css,scss,sass,less,ts,tsx,js,jsx";W.plugins.push(new S({fix:!0,files:[r(y.programPath,`${I.alias["@"]}/**/*.{${e}}`).replace(/\\/g,"/"),B&&r(y.programPath,`${I.alias["@pkg"]}/**/*.{${e}}`).replace(/\\/g,"/")].filter(Boolean),cache:!0,cacheLocation:`${y.lintCachePath}/.stylelintcache`}))}if(I.bar){let e=I.bar,t=e.name||"Build";W.plugins.push(new d.ProgressPlugin({handler(o,r,...i){p(o||0,1,{msg:i.length?`[${r}] ${i.join(" ")}`:"",name:t,barColor:e.barColor,nameColor:e.nameColor,barBgColor:e.barBgColor,msgColor:e.msgColor}),1===o&&process.stdout.write("\r\x1b[2K")}}))}let F=d(W);F.hooks.done.tap("client-log",e=>{k(null,e)});let N={};if(I.devServer.https){let[e,t]=await Promise.all([n(I.devServer.https.key),n(I.devServer.https.cert)]);e||(m(l(`法加载私钥。请检查路径和文件是否存在,并确保路径正确:${I.devServer.https.key}`,"red")),process.exit(1)),t||(m(l(`无法加载证书。请检查路径和文件是否存在,并确保路径正确:${I.devServer.https.cert}`,"red")),process.exit(1)),N.http2=!0,N.https={key:e,cert:t}}let K=u(F,{writeToDisk:!1,index:"index.html",headers:e=>({"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Headers":"DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization","Access-Control-Allow-Methods":"GET, POST, OPTIONS, DELETE, PATCH, PUT",...I.devServer.headers,"Access-Control-Allow-Origin":e.headers.origin||"*","Cache-Control":"no-store, no-cache, must-revalidate, proxy-revalidate",Pragma:"no-cache",Expires:"0"}),serverSideRender:!1,lastModified:!0,publicPath:W.output?.publicPath,cacheControl:!1,cacheImmutable:!1}),X=h(F,{log:!1,path:D,heartbeat:2e3}),J=c({logger:!1,...N});await J.register(s),J.use(K),J.use(D,X),b(J,{directory:y.mockPath}),j(J,I.proxy);let Q=`${W.output.path}/index.html`;function V(){process.exit(0)}J.get("*",async(e,t)=>{if(e.headers.accept?.includes("text/html")){let e=K.context.outputFileSystem,o=e?.readFileSync?.(Q);if(!t.sent){t.type("text/html").send(o);return}}else if(e.url?.endsWith(D)&&"text/event-stream"===e.headers.accept){e.raw.url=D,X(e.raw,t.raw,A);return}}),J.addHook("onClose",()=>{K.close(A),J.server.close(A)}),await J.register(i,{global:!0}),J.listen({port:$});let Y=await Promise.all(x.map(M)),Z=f(Y[0]||{},Y[1]||{});x.forEach(function(t){o(t,async function(){let[o,r]=await Promise.all(x.map(M)),i=f(o||{},r||{}),s=g(Z,i);1===Object.keys(s).length&&"proxy"in s?(a(l(`代理更新中...`,"yellow"),!0),await j(J,i.proxy),a(l(`代理更新完成...`,"green"),!0),I.proxy=i.proxy,Z.proxy=i.proxy,Z=i):(Z=i,m(l(`检测到工程配置${l(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),e("win32"===process.platform?`netstat -ano | findstr :${$}`:`lsof -i :${$} -t`,(e,t)=>{if(e){m(l(`查找端口 ${$} 时发生错误: ${e.message}`,"red")),m(l("请尝试手动重启程序","yellow"));return}let o=t.trim().split("\n").filter(Boolean),r=ee?o[0]?.split(/\s+/).pop()?.trim():o[0]?.trim();if(!r){m(l(`未找到占用端口 ${$} 的进程, 请尝试手动重启程序`,"yellow"));return}try{process.kill(Number(r),"SIGHUP")}catch(e){m(l(`终止进程 ${r} 时发生错误: ${e.message}`,"red"))}}))})});let ee="win32"===process.platform;process.on("SIGHUP",function(){J.close(A),function(){let e=t(process.argv[0],process.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",V)}()}),process.on("exit",function(){J.close(A)}),C(V);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { transformSync } from '@swc/core';
|
|
2
|
+
import swcrc, { SwcOption } from '../options/swcrc.mjs';
|
|
3
|
+
import { isDev } from '../process-env.mjs';
|
|
4
|
+
import info from '../vm/info.mjs';
|
|
5
|
+
declare const version: number;
|
|
6
|
+
declare const ReactDomPath: string;
|
|
7
|
+
declare const isHashRouter: boolean;
|
|
8
|
+
declare const v7Future: Record<string, boolean | undefined>;
|
|
9
|
+
declare const createRouter: string;
|
|
10
|
+
declare const code: string;
|
|
11
|
+
declare const swcOption: SwcOption;
|
|
12
|
+
declare const reactRenderApp: string;
|
|
13
|
+
export default reactRenderApp;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import{transformSync as e}from"@swc/core";import r from"../options/swcrc.mjs";import{isDev as t}from"../process-env.mjs";import o from"../vm/info.mjs";let a=parseFloat(o.frameworkVersion),n="hash"===o.routerMode,s=Object.assign({v7_relativeSplatPath:!1},"browser"===o.routerMode?{v7_fetcherPersist:!1,v7_normalizeFormMethod:!1,v7_partialHydration:o.ssr,v7_skipActionErrorRevalidation:!1}:{}),c=n?"createHashRouter":"createBrowserRouter",p=`import React, { StrictMode, useRef, type ReactElement } from 'react';
|
|
2
|
+
import Fallback from '@app/fallback';
|
|
3
|
+
import routes from '@app/routes';
|
|
4
|
+
import ReactDOM from '${a<18?"react-dom":"react-dom/client"}';
|
|
5
|
+
import { RouterProvider, ${c} } from 'react-router-dom';
|
|
6
|
+
|
|
7
|
+
type RenderAppProps = {
|
|
8
|
+
container?: HTMLElement;
|
|
9
|
+
basename?: string;
|
|
10
|
+
fallback?: ReactElement;
|
|
11
|
+
language?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function App(props: RenderAppProps) {
|
|
15
|
+
const v7Future = useRef(${JSON.stringify(s)});
|
|
16
|
+
return (
|
|
17
|
+
<StrictMode>
|
|
18
|
+
<RouterProvider
|
|
19
|
+
router={${c}(routes, {
|
|
20
|
+
basename: ${n?"/":"props.basename"},
|
|
21
|
+
window: window,
|
|
22
|
+
future: v7Future.current,
|
|
23
|
+
})}
|
|
24
|
+
future={{
|
|
25
|
+
/** 这使用 useTransition 而不是 useState 来更新路由器状态 */
|
|
26
|
+
v7_startTransition: false,
|
|
27
|
+
}}
|
|
28
|
+
fallbackElement={Fallback && <Fallback />}
|
|
29
|
+
/>
|
|
30
|
+
</StrictMode>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function renderApp(props: RenderAppProps = {}) {
|
|
35
|
+
const { container, basename = "${o.base}", language, ...args } = props;
|
|
36
|
+
const _container = container?.querySelector('#root') || document.getElementById('root');
|
|
37
|
+
${"micro"===o.type?"window.mainApp = { ...args, container: _container as HTMLElement };":""}
|
|
38
|
+
${a<18?`ReactDOM.${t?"render":"hydrate"}(<App basename={basename} language={language} />, _container);return () => ReactDOM.unmountComponentAtNode(_container as Element);`:"const instance = ReactDOM.createRoot(_container as HTMLElement);instance.render(<App basename={basename} language={language} />);return instance.unmount;"}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default renderApp;`,i=r(o.ssr);delete i.sync,delete i.parseMap;let m=e(p,i).code;console.log(m);export default m;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e;Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return u}});const t=require("lightningcss"),r=(e=require("../../commom/log.mjs"))&&e.__esModule?e:{default:e},
|
|
1
|
+
"use strict";var e;Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return u}});const t=require("lightningcss"),r=(e=require("../../commom/log.mjs"))&&e.__esModule?e:{default:e},s=require("./codegen.cjs"),i=require("./utils.cjs");function o(e,t){return JSON.stringify(e.utils.contextify(e.context||e.rootContext,t))}const l=new TextEncoder,n={Declaration:{custom(e){if("content"===e.name&&1===e.value.length){let t=e.value[0];if("token"===t.type&&"string"===t.value.type)return[{property:e.name,raw:JSON.stringify(t.value.value.replace(/[\u4e00-\u9faF]/g,function(e){return`\\${e.charCodeAt(0).toString(16)}`}))}]}}}};async function u(e,u){let _=this.async();this.cacheable&&this.cacheable();let{implementation:a,visitor:p,rem:c,...f}=this.getOptions(),m=!!f.modules?.auto?.(this.resourcePath);if(m&&void 0===f.modules.namedExport&&(f.modules.namedExport=!0),a&&"function"!=typeof a.transform){_(TypeError(`[lightning-loader]: implementation.transform must be an 'lightningcss' transform function. Received ${typeof a.transform}`));return}let d=[],h=[],R=[],S=[],g=[];f.modules?.exportOnlyLocals!==!0&&h.unshift({type:"api_import",importName:"___CSS_LOADER_API_IMPORT___",url:o(this,require.resolve("./runtime/api.cjs"))});let y=a?.transform?a.transform:t.transform,L=new Map,O=new Map,E=new Map,v=function(e,t,r,s,o,l){let n=new Map,u=!1,_=new Map,a=new Map,p=-1,c=-1;return{Rule:{import(s){let o;if(e.importFilter&&!e.importFilter(s.value.url,s.value.media))return s;let u=s.value.url;c++,l.set(c,u),u=`__MO_LIGHTNINGCSS_LOADER_IMPORT_URL_REPLACE_${c}__`;let _=s.value.media.mediaQueries.length?JSON.stringify(s.value.media.mediaQueries):void 0,a=(0,i.isUrlRequestable)(u);if(a){let e=u.split("!");e.length>1&&(u=e.pop(),o=e.join("!"))}if(!a)return t.push({url:u,media:_}),{type:"ignored",value:""};let p=o?`${o}!${u}`:u,f=n.get(p);if(!f){f=`___CSS_LOADER_AT_RULE_IMPORT_${n.size}___`,n.set(p,f);let t=e.urlHandler(p);r.push({type:"rule_import",importName:f,url:t})}return t.push({importName:f,media:_}),{type:"ignored",value:""}}},Url:t=>(function(t){let l,n=t.url;if(!e.urlFilter(n)||(0,i.isDataUrl)(n))return t;p++,o.set(p,n);let[,c,f]=(n=`__MO_LIGHTNINGCSS_LOADER_URL_REPLACE_${p}__`).split(/(\?)?#/,3),m=n.split("!");m.length>1&&(n=m.pop(),l=m.join("!"));let d=c?"?":"";d+=f?`#${f}`:"",u||(r.push({type:"get_url_import",importName:"___CSS_LOADER_GET_URL_IMPORT___",url:JSON.stringify(require.resolve("./runtime/get-url.cjs")),index:-1}),u=!0);let h=l?`${l}!${n}`:n,R=_.get(h);R||(R=`___CSS_LOADER_URL_IMPORT_${_.size}___`,_.set(h,R),r.push({type:"url",importName:R,url:JSON.stringify(h),index:p}));let S=JSON.stringify({newUrl:h,hash:d,needQuotes:!1}),g=a.get(S);return g||(g=`___CSS_LOADER_URL_REPLACEMENT_${a.size}___`,a.set(S,g),s.push({replacementName:g,importName:R,hash:d,needQuotes:!1})),{loc:t.loc,url:g}})(t)}}({urlHandler:e=>o(this,(0,i.getPreRequester)(this)(f.importLoaders??0)+e),urlFilter:(0,i.getFilter)(f.url,this.resourcePath),importFilter:(0,i.getFilter)(f.import,this.resourcePath),context:this.context},S,h,g,L,E),C=function({apis:e,imports:t,replacements:r,replacedUrls:s,urlHandler:i}){let o=-1,l=-1;return{Declaration:{composes(n){if("unparsed"===n.property)return;let u=n.value.from;if(u?.type!=="file")return;let _=u.value;if(!_)return;o++,s.set(o,_),_=`__MO_LIGHTNINGCSS_LOADER_ICSS_URL_REPLACE_${o}__`;let a=`___CSS_LOADER_ICSS_IMPORT_${t.length}___`;t.push({type:"icss_import",importName:a,icss:!0,url:i(_),index:o}),e.push({importName:a,dedupe:!0,index:o});let p=[];for(let e of n.value.names){l++;let t=`___CSS_LOADER_ICSS_IMPORT_${o}_REPLACEMENT_${l}___`;r.push({replacementName:t,importName:a,localName:e}),p.push(t)}return{property:"composes",value:{loc:n.value.loc,names:p,from:u}}}}}}({apis:S,imports:R,replacements:g,replacedUrls:O,urlHandler:e=>o(this,(0,i.getPreRequester)(this)(f.importLoaders)+e)});try{c&&!n.Length&&(n.Length=function(e){if("px"===e.unit)return{unit:"rem",value:e.value/16}});let{code:t,map:r,exports:o}=y({filename:this.resourcePath,code:l.encode(e),minify:!0,visitor:{...n,...v,...C,...p},cssModules:!!m&&{pattern:f.modules.localIdentName},sourceMap:this.sourceMap,inputSourceMap:this.sourceMap&&u?JSON.stringify(u):void 0,analyzeDependencies:!1,drafts:{customMedia:!0},include:1,errorRecovery:!1,unusedSymbols:[],...f}),a=t.toString();if(o){for(let e in o)if(Object.prototype.hasOwnProperty.call(o,e)){let t=o[e],r=t.name;for(let e of t.composes)r+=` ${e.name}`;d.push({name:e,value:r})}f.modules.getJSON?.({resourcePath:this.resourcePath,exports:d})}if(0!==L.size){let e=this.getResolve({conditionNames:["asset"],mainFields:["asset"],mainFiles:[],extensions:[]});for(let[t,r]of L.entries()){let[s]=r.split(/(\?)?#/,3),o=(0,i.requestify)(s,this.rootContext),l=await (0,i.resolveRequests)(e,this.context,[...new Set([o,r])]);for(let e of h)e.url=e.url.replace(`__MO_LIGHTNINGCSS_LOADER_URL_REPLACE_${t}__`,l??r)}}if(0!==E.size){let e=this.getResolve({conditionNames:["style"],extensions:[".css"],mainFields:["css","style","main","..."],mainFiles:["index","..."],restrictions:[/\.css$/i]});for(let[t,r]of E.entries()){let[s]=r.split(/(\?)?#/,3),o=(0,i.requestify)(s,this.rootContext),l=await (0,i.resolveRequests)(e,this.context,[...new Set([o,r])]);for(let e of h)e.url=e.url.replace(`__MO_LIGHTNINGCSS_LOADER_IMPORT_URL_REPLACE_${t}__`,l??r)}}if(0!==O.size){let e=this.getResolve({conditionNames:["style"],extensions:[],mainFields:["css","style","main","..."],mainFiles:["index","..."]});for(let[t,r]of O.entries()){let[s]=r.split(/(\?)?#/,3),o=(0,i.requestify)(s,this.rootContext),l=await (0,i.resolveRequests)(e,this.context,[...new Set([r,o])]);for(let e of R)e.url=e.url.replace(`__MO_LIGHTNINGCSS_LOADER_ICSS_URL_REPLACE_${t}__`,l??r)}}h.push(...R);let M=(0,s.getImportCode)(h,f),N=(0,s.getModuleCode)({css:a,map:r},S,g,f,this),x=(0,s.getExportCode)(d,g,f),P=`${M}${N}${x}`;_(null,P,r&&JSON.parse(r.toString()))}catch(e){_(e),(0,r.default)(e)}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";module.exports=function(e,
|
|
1
|
+
"use strict";module.exports=function(e,a){return(a||(a={}),"string"!=typeof(e=e&&e.__esModule?e.default:e))?"Buffer"===e.type&&e.data?`data:${function(e){let a=(function(e,a=0){return e.slice(a,16).map(e=>e.toString(16).padStart(2,"0")).join("")})(e,0).toLowerCase();for(let[e,f]of Object.entries({"0001000000":"font/ttf","4f54544f":"font/otf","774f4646":"font/woff","774f4632":"font/woff2","89504e470d0a1a0a":"image/png",ffd8ffe0:"image/jpeg",ffd8ffdb:"image/jpeg",ffd8ffee:"image/jpeg",ffd8ffe000104a4649460001:"image/jpeg","ffd8ffe1????457869660000":"image/jpeg","0000000c4a584c200d0a870a":"image/jxl","474946383761":"image/gif","474946383961":"image/gif","49492a00":"image/tif","49492b00":"image/tif","4d4d002a":"image/tiff","4d4d002b":"image/tiff","52494646????????57454250":"image/webp","424d":"image/bmp","00000100":"image/x-icon","69636e73":"image/x-icns","6674797068656963":"image/heic","667479706d":"image/heic",ff4fff51:"image/jp2","0000000c6a5020200d0a870a":"image/jp2","667479704d534e56":"video/mp4","6674797069736f6d":"video/mp4","1a45dfa3":"video/webm","52494646????????41564920":"video/avi","000001ba":"video/mpeg","000001b3":"video/mpeg","464c56":"video/x-flv",494433:"audio/mpeg","4f676753":"audio/ogg","52494646????????57415645":"audio/wav","664c6143":"audio/flac","4d546864":"audio/midi","3026b2758e66cf11a6d900aa0062ce6c":"application/x-ms-asf"}))if(a.startsWith(e))return f;return"unknown"}(e.data)};base64,${btoa(Array.from(e.data,e=>String.fromCharCode(e)).join(""))}`:e:(/^['"].*['"]$/.test(e)&&(e=e.slice(1,-1)),a.hash&&(e+=a.hash),/["'() \t\n]/.test(e)||a.needQuotes)?'"'.concat(e.replace(/"/g,'\\"').replace(/\n/g,"\\n"),'"'):e};
|
|
@@ -4,4 +4,6 @@ type Url = {
|
|
|
4
4
|
type?: string;
|
|
5
5
|
data?: number[];
|
|
6
6
|
};
|
|
7
|
-
declare function
|
|
7
|
+
declare function uint8ArrayToBase64(numberArray: number[]);
|
|
8
|
+
declare function numberArrayToHex(buffer: number[], start?: number);
|
|
9
|
+
declare function getMimeType(buffer: number[]);
|
package/lib/module.config.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let e;import{join as o,sep as s}from"node:path";import{saveFileSync as t}from"@moneko/utils";import r,{CUSTOMCONFIG as a}from"./commom/paths.mjs";import m from"./commom/reactive-object.mjs";import n from"./commom/require.mjs";import i from"./commom/rule.mjs";import l from"./options/css-extract.mjs";import c from"./options/modify-vars.mjs";import d from"./options/reslove.mjs";import p from"./options/swcrc.mjs";import{getLightningCssTargets as u}from"./polyfills/targets.mjs";import{node_modules as f,resolveProgram as
|
|
2
|
-
`)}:void 0},importLoaders:2}},k={loader:d.lessLoader,options:{sourceMap:!!w.sourceMap,lessOptions:{modifyVars:c,javascriptEnabled:!0}}},C=new Map;function O(e){if(C.has(e))return C.get(e);try{let o;let t=n.resolve(e).split(s),r=t.lastIndexOf("node_modules");return o=-1!==r?t.slice(0,r).join(s):t.join(s),C.set(e,o),o}catch{let o=f(e);return C.set(e,o),o}}let I=[...w.cssModules,`@moneko/${L}`,"neko-ui"].map(O),b=["components","example","mock","site","src","server"].map(
|
|
1
|
+
let e;import{join as o,sep as s}from"node:path";import{saveFileSync as t}from"@moneko/utils";import r,{CUSTOMCONFIG as a}from"./commom/paths.mjs";import m from"./commom/reactive-object.mjs";import n from"./commom/require.mjs";import i from"./commom/rule.mjs";import l from"./options/css-extract.mjs";import c from"./options/modify-vars.mjs";import d from"./options/reslove.mjs";import p from"./options/swcrc.mjs";import{getLightningCssTargets as u}from"./polyfills/targets.mjs";import{node_modules as f,resolveProgram as h,toCamelCase as j}from"./utils/index.mjs";import v from"./utils/svg-to-data-uri.mjs";import{comment as g,getCommentPath as x}from"./vm/docs.mjs";import y from"./vm/generate-doc.mjs";import{CONFIG as w}from"./config.mjs";import{FRAMEWORK as L,isDev as P,isLibrary as M}from"./process-env.mjs";let _={loader:o(r.corePath,"/loader/lightning-css/loader.cjs"),options:{sourceMap:!!w.sourceMap,targets:u(),rem:!!w.rem,esModule:!0,modules:{auto(e){if(e){if(e.endsWith(".css")&&!e.endsWith("module.css"))return!1;for(let o=0,s=I.length;o<s;o++)if(e.includes(I[o]))return i.css_module.test(e)}return i.node_modules_css_module.test(e)},localIdentName:"[name][hash]_[local]",namedExport:!0,exportLocalsConvention:"dashesOnly",exportOnlyLocals:!1,getJSON:w.cssModuleDefinition?function(e){Q.setData(`${e.resourcePath}.d.ts`,`${e.exports.map(({name:e,value:o})=>`export const ${j(e)}: '${o}';`).join("\n")}
|
|
2
|
+
`)}:void 0},importLoaders:2}},k={loader:d.lessLoader,options:{sourceMap:!!w.sourceMap,lessOptions:{modifyVars:c,javascriptEnabled:!0}}},C=new Map;function O(e){if(C.has(e))return C.get(e);try{let o;let t=n.resolve(e).split(s),r=t.lastIndexOf("node_modules");return o=-1!==r?t.slice(0,r).join(s):t.join(s),C.set(e,o),o}catch{let o=f(e);return C.set(e,o),o}}let I=[...w.cssModules,`@moneko/${L}`,"neko-ui"].map(O),b=["components","example","mock","site","src","server"].map(h);function W(e){return new Promise(o=>{o([...b,r.corePath,...w.rulesInclude?.[e]?.map(O)||[]])})}a&&b.push(h(a)),w.overrideResolve&&w.overrideResolve.override&&b.push(w.overrideResolve.override);let $=await Promise.all([W("css"),W("js"),W("media"),W("wasm"),W("font")]),R=$[0],B=$[1],S=$[2],z=$[3],D=$[4];d.sassLoader&&(e={loader:d.sassLoader,options:{implementation:await import("sass"),sassOptions:{}}});let E=M&&P&&{test:i.tsdoc,include:w.alias["@pkg"],exclude:[/node_modules\/(?!(@app|@moneko)).+/,i.__tests__],enforce:"pre",loader:o(r.corePath,"/loader/ts-doc.cjs"),options:{comment:g,generateDoc:y,getCommentPath:x}},J=[{resourceQuery:/raw/i,type:"asset/source"},{resourceQuery:/url/i,type:"asset/resource",generator:{filename(e){let o=e.filename;return o&&o.toLocaleLowerCase().endsWith("wasm?url")?"wasm/[name][ext]":"assets/[name][ext]"}}},{test:i.wasm,type:"webassembly/async",include:z},{test:i.txt,type:"asset/source"},{test:i.image,type:"asset",dependency:{not:["url"]},parser:{dataUrlCondition:{maxSize:4096}},generator:{filename:e=>e.filename?.toLocaleLowerCase().endsWith(".svg")?"assets/svg/[name][ext]":"assets/images/[name][ext]",dataUrl:(e,o)=>o.filename.toLocaleLowerCase().endsWith(".svg")?v(e.toString()):e},include:S},{test:i.video,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/video/[name][ext]"},include:S},{test:i.font,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/fonts/[name][ext]"},include:D}],N=w.prefixJsLoader.filter(Boolean)||[];switch(L){case"react":w.reactCompiler&&N.unshift({loader:o(r.corePath,"/loader/react-compiler.cjs"),options:w.reactCompiler});break;case"solid":w.refresh=!1}let Q=new m({});Q.on("change",(e,o)=>{t(e,o)});export default(s=>{let t={loader:d.swcLoader,options:p(s)};return{parser:{javascript:{commonjsMagicComments:!0,dynamicImportMode:"lazy",dynamicImportPrefetch:!1,dynamicImportPreload:!1,importMeta:!0,importMetaContext:!0}},noParse:w.noParse,rules:[!1!==w.htmlPluginOption&&E,{oneOf:[...J,{test:i.js,use:[...N,t],include:B},{test:i.css,use:[l,_],include:R},e&&{test:i.scss,use:[l,_,e],include:R},{test:i.less,use:[l,_,k],include:R},{test:i.markdown,use:[...N,{loader:o(r.corePath,"/loader/mdx.cjs"),options:w.mdx}],exclude:[/node_modules\/(?!(@app|@moneko)).+/]}].filter(Boolean)},...w.moduleRules].filter(Boolean)}});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { CONFIG } from '../config.mjs';
|
|
2
|
+
import type { HtmlPluginOption } from '../plugin/html-plugin.mjs';
|
|
2
3
|
declare const prefixCls: string;
|
|
4
|
+
declare const favicon: string;
|
|
3
5
|
declare const modifyVars: Record<string, string | false | undefined>;
|
|
4
6
|
export default modifyVars;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CONFIG as i}from"../config.mjs";let f=i.prefixCls||"n",n={"@prefix-cls":f,"@ant-prefix":f,"@iconfont-css-prefix":`${f}-icon`,"@favicon":i.
|
|
1
|
+
import{CONFIG as i}from"../config.mjs";let f=i.prefixCls||"n",n=i.htmlPluginOption?.favicon||"favicon.ico",o={"@prefix-cls":f,"@ant-prefix":f,"@iconfont-css-prefix":`${f}-icon`,"@favicon":JSON.stringify(`${i.publicPath||""}${n}`)};Object.assign(o,i.modifyVars);export default o;
|
package/lib/options/swcrc.d.mts
CHANGED
|
@@ -9,6 +9,13 @@ import reslove from './reslove.mjs';
|
|
|
9
9
|
declare function transformConfigs(config: SwcImportOnDemandTransform);
|
|
10
10
|
declare const importOnDemand: SwcImportOnDemandTransform;
|
|
11
11
|
declare const env: EnvConfig;
|
|
12
|
+
export type SwcOption = SwcConfig & {
|
|
13
|
+
module?: {
|
|
14
|
+
resolveFully: boolean;
|
|
15
|
+
};
|
|
16
|
+
parseMap?: boolean;
|
|
17
|
+
sync?: boolean;
|
|
18
|
+
};
|
|
12
19
|
declare const _dts_1: (ssr: boolean, other: {
|
|
13
20
|
}) => any;
|
|
14
21
|
export default _dts_1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as t,readFileSync as e}from"node:fs";import{basename as s,resolve as i}from"node:path";import
|
|
1
|
+
import{existsSync as t,readFileSync as e}from"node:fs";import{basename as s,resolve as i}from"node:path";import o from"webpack";export class HtmlPlugin{constructor(t={}){this.AddEntry=/main\.bundle\.js$/,this.faviconPath="",this.name="HtmlPlugin",this.cachedMetaTags=null,this.cachedCustomTags=null,this.options={title:"WebApp",filename:"index.html",inject:"head",...t}}apply(n){n.hooks.compilation.tap(this.name,a=>{a.hooks.processAssets.tap({name:this.name,stage:o.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL},()=>{let h;if(this.options.favicon){let h=i(n.context,this.options.favicon);if(t(h)){let t=s(this.options.favicon),i=e(h);a.emitAsset(t,new o.sources.RawSource(i),{javascriptModule:!1}),this.faviconPath=(a.outputOptions.publicPath||"")+t}else a.warnings.push(new o.WebpackError(`Favicon file ${h} does not exist`))}if(h=this.options.templateContent?this.options.templateContent(this.options):this.options.template?e(i(n.context,this.options.template),{encoding:"utf-8"}):this.generateDefaultTemplate(),this.options.inject){let t=this.getAssets(a);h=this.injectAssets(h,t,this.options.inject)}let r="function"==typeof this.options.filename?this.options.filename("index"):this.options.filename||"index.html";a.emitAsset(r,new o.sources.RawSource(h),{javascriptModule:!1})})})}generateDefaultTemplate(){let t=this.generateMetaTags(),e=this.generateCustomTags();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}">${e.head}</head><body><div id="root"></div>${e.body}</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(" "),r=`<${i} ${h}>${o}</${i}>`;"head"===n?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=t.outputOptions.publicPath||"";for(let i of t.entrypoints.values())for(let t of i.chunks)for(let i of t.files)i.endsWith(".js")?e.js.push(s+i):i.endsWith(".css")&&e.css.push(s+i);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/lib/plugins.config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"webpack";import{CopyPlugin as t}from"./plugin/copy.mjs";import{HtmlPlugin as i}from"./plugin/html-plugin.mjs";import o from"./plugin/module-federation.mjs";import{VirtualModuleWebpackPlugin as l}from"./plugin/virtual-module.mjs";import{CONFIG as
|
|
1
|
+
import e from"webpack";import{CopyPlugin as t}from"./plugin/copy.mjs";import{HtmlPlugin as i}from"./plugin/html-plugin.mjs";import o from"./plugin/module-federation.mjs";import{VirtualModuleWebpackPlugin as l}from"./plugin/virtual-module.mjs";import{CONFIG as r}from"./config.mjs";import{description as n,keywords as p}from"./process-env.mjs";let a=[...o,new l(r.virtualModule),new t(r.copy),new e.DefinePlugin({"process.env":JSON.stringify(r.env)}),new e.IgnorePlugin({resourceRegExp:/\/(__(tests|mocks)__|test|spec|e2e)\//}),...r.plugins].filter(Boolean);if(r.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:n,keywords:Array.isArray(p)?p.toString():"","http-equiv":"refresh",viewport:"width=device-width, initial-scale=1"};r.seo&&(e.relCanonical={rel:"canonical",href:`https://${r.seo.domain}${r.basename}`}),r.htmlPluginOption.meta&&Object.assign(e,r.htmlPluginOption.meta),a.push(new i({...r.htmlPluginOption,meta:e}))}if(r.fixBrowserRouter){let e=r.basename.split("/").filter(Boolean).length,t=`${Array(e).fill("..").join("/")+(e?"/":"")}404.html`,o=r.fixBrowserRouter.pathSegmentsToKeep??e;a.push(new i({filename:r.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>`}))}r.sourceMap&&a.push(new e.SourceMapDevToolPlugin(r.sourceMap));export default a;
|
package/lib/process-env.d.mts
CHANGED
|
@@ -12,6 +12,9 @@ export declare const isSolid: boolean;
|
|
|
12
12
|
export declare const SSR: boolean;
|
|
13
13
|
export declare const mainDirectory: 'site' | 'src';
|
|
14
14
|
export declare const jsxImportSource: string;
|
|
15
|
+
export declare const framework: 'react' | 'solid-js';
|
|
16
|
+
export declare const frameworkVersionStr: string;
|
|
17
|
+
export declare const frameworkVersion: number;
|
|
15
18
|
declare const info: Record<string, unknown>;
|
|
16
19
|
export declare const description: string;
|
|
17
20
|
export declare const author: string | Record<string, string>;
|
package/lib/process-env.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import o from"./commom/has-pkg.mjs";import r from"./commom/require.mjs";export const APPTYPE=process.env.APPTYPE;export const FRAMEWORK=process.env.FRAMEWORK;export const NODE_ENV=process.env.NODE_ENV;export const isLibrary="library"===APPTYPE;export const isMicro="micro"===APPTYPE;export const isMobile="mobile"===APPTYPE;export const isReact="react"===FRAMEWORK;export const isSolid="solid"===FRAMEWORK;export const SSR="true"===process.env.SSR;export const mainDirectory=isLibrary?"site":"src";export const jsxImportSource={react:"react",solid:"solid-js/h"}[FRAMEWORK];let e=r(`${process.cwd()}/package.json`);export const description=e.description;export const author=e.author;export const repository=e.repository;export const keywords=e.keywords;export const PACKAGENAME=e.name;export const PACKAGEVERSION=e.version;export const coreName="@moneko/core";export const isDev="development"===NODE_ENV;export const refresh=!!(isDev&&(o("solid-refresh")||o("react-refresh")));
|
|
1
|
+
import o from"./commom/has-pkg.mjs";import r from"./commom/require.mjs";export const APPTYPE=process.env.APPTYPE;export const FRAMEWORK=process.env.FRAMEWORK;export const NODE_ENV=process.env.NODE_ENV;export const isLibrary="library"===APPTYPE;export const isMicro="micro"===APPTYPE;export const isMobile="mobile"===APPTYPE;export const isReact="react"===FRAMEWORK;export const isSolid="solid"===FRAMEWORK;export const SSR="true"===process.env.SSR;export const mainDirectory=isLibrary?"site":"src";export const jsxImportSource={react:"react",solid:"solid-js/h"}[FRAMEWORK];export const framework={react:"react",solid:"solid-js"}[FRAMEWORK];export const frameworkVersionStr=r(`${framework}/package.json`).version;export const frameworkVersion=parseFloat(frameworkVersionStr);let e=r(`${process.cwd()}/package.json`);export const description=e.description;export const author=e.author;export const repository=e.repository;export const keywords=e.keywords;export const PACKAGENAME=e.name;export const PACKAGEVERSION=e.version;export const coreName="@moneko/core";export const isDev="development"===NODE_ENV;export const refresh=!!(isDev&&(o("solid-refresh")||o("react-refresh")));
|
package/lib/vm/docs.d.mts
CHANGED
|
@@ -5,10 +5,9 @@ import paths from '../commom/paths.mjs';
|
|
|
5
5
|
import ReactiveObject from '../commom/reactive-object.mjs';
|
|
6
6
|
import Rule from '../commom/rule.mjs';
|
|
7
7
|
import { CONFIG } from '../config.mjs';
|
|
8
|
-
import { FRAMEWORK, isLibrary, isReact, isSolid } from '../process-env.mjs';
|
|
8
|
+
import { FRAMEWORK, framework, isLibrary, isReact, isSolid } from '../process-env.mjs';
|
|
9
9
|
import generateDoc from './generate-doc.mjs';
|
|
10
10
|
declare const createElement: string;
|
|
11
|
-
declare const FRAMEWORKNAME: string;
|
|
12
11
|
declare const moduleMeta: ModuleMeta;
|
|
13
12
|
export declare const docsModuleName: string;
|
|
14
13
|
export declare const docsModulePkgJson: string;
|
package/lib/vm/docs.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{relative as e,sep as t}from"node:path";import{loadFile as o,scanFolderSync as m}from"@moneko/utils";import a from"../commom/parse-module-meta.mjs";import
|
|
1
|
+
import{relative as e,sep as t}from"node:path";import{loadFile as o,scanFolderSync as m}from"@moneko/utils";import a from"../commom/parse-module-meta.mjs";import n from"../commom/paths.mjs";import r from"../commom/reactive-object.mjs";import s from"../commom/rule.mjs";import{CONFIG as l}from"../config.mjs";import{FRAMEWORK as c,framework as p,isLibrary as i,isReact as d,isSolid as f}from"../process-env.mjs";import u from"./generate-doc.mjs";let g={react:"createElement",solid:"createComponent"}[c],h=a("@app/docs");export const docsModuleName=h.file;export const docsModulePkgJson=h.pkg;export const docsModuleMeta=h.meta;export const docs=new r({[docsModuleName]:"export default {}",[docsModulePkgJson]:docsModuleMeta});export const comment=new r({});export const getCommentPath=function(){let e=/\/(.+?)\.tsx?$/,t=l.alias["@pkg"]?.length;return o=>o.substring(t).replace(/\\/g,"/").replace(e,"@app/comment/$1.md")}();if(i&&!1!==l.htmlPluginOption){let r={},c=`import { ${g}${f?",Dynamic":""} } from "${p}${f?"/web":""}";import SuspenseComp from "@app/suspense";function call_then(res) {return {default: ${d?"() =>":""}${g}(${f?"Dynamic":"'div'"}, {${f?"innerHTML: res.default, component: 'div', class: 'n-md-box' ":"dangerouslySetInnerHTML: {__html:res.default}, className: 'n-md-box'"} })};}`,i=(e,o)=>{if(!e.endsWith("package.json")){let m=e.replace(/@app[/\\]comment[/\\]/,"").split(t),a=m.pop(),n=m.join("/");r[n]||(r[n]={}),o?r[n][a]&&delete r[n][a]:r[n][a]=`rr(() => ${g}(SuspenseComp, { comp: () => import(/* webpackChunkName: '${e}' */ '${e}?raw').then(call_then)}))rr`;let l={};for(let e in r)Object.prototype.hasOwnProperty.call(r,e)&&(l[e]=Object.values(r[e]));docs.setData(docsModuleName,`${c}export default ${JSON.stringify(l).replace(s.extract_func,"$1")}`)}};comment.on("change",(t,o)=>{i(e(n.nodeModules,t),o?.length<0)});let h=m(l.alias["@pkg"],["\\.tsx?$"]).filter(e=>!/(^|\/)\.[^\\/\\.]|\.test\./i.test(e));await Promise.all(h.map(async e=>({data:await o(e),file:e}))).then(e=>{for(let t=0;t<e.length;t++){let o=e[t];if(o.data){let{file:e,pkg:t,meta:m}=a(getCommentPath(o.file));comment.setData(e,u(o.data,o.file)),comment.setData(t,m)}}})}
|
package/lib/vm/info.d.mts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import require from '../commom/require.mjs';
|
|
2
1
|
import { CONFIG } from '../config.mjs';
|
|
3
|
-
import { APPTYPE, author, description,
|
|
2
|
+
import { APPTYPE, author, description, framework, frameworkVersionStr, PACKAGENAME, PACKAGEVERSION, repository, SSR } from '../process-env.mjs';
|
|
4
3
|
import { convertToCamelCase } from '../utils/index.mjs';
|
|
5
|
-
declare const framework: string;
|
|
6
|
-
declare const frameworkVersion: string;
|
|
7
4
|
declare const iStr: boolean;
|
|
8
5
|
declare const app: {
|
|
9
6
|
readonly name;
|
|
@@ -19,5 +16,6 @@ declare const app: {
|
|
|
19
16
|
readonly author;
|
|
20
17
|
readonly repository;
|
|
21
18
|
readonly frameworkVersion;
|
|
19
|
+
readonly framework;
|
|
22
20
|
};
|
|
23
21
|
export default app;
|
package/lib/vm/info.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import{CONFIG as e}from"../config.mjs";import{APPTYPE as r,author as o,description as t,framework as m,frameworkVersionStr as s,PACKAGENAME as i,PACKAGEVERSION as p,repository as a,SSR as f}from"../process-env.mjs";import{convertToCamelCase as n}from"../utils/index.mjs";let l="string"==typeof o,u={name:i,projectName:n(i),ssr:f,version:p,base:e.basename,type:r,routerMode:e.routerMode,prefixCls:e.prefixCls,theme:e.theme,description:t,author:l?{name:o}:o,repository:l?{url:a}:a,frameworkVersion:s,framework:m};export default u;
|
package/lib/vm/modules.d.mts
CHANGED
|
@@ -7,6 +7,7 @@ import paths from '../commom/paths.mjs';
|
|
|
7
7
|
import Rule from '../commom/rule.mjs';
|
|
8
8
|
import { CONFIG } from '../config.mjs';
|
|
9
9
|
import moduleFederation from '../plugin/module-federation.mjs';
|
|
10
|
+
import type { VirtualModulePluginOption } from '../plugin/virtual-module.mjs';
|
|
10
11
|
import { APPTYPE, FRAMEWORK } from '../process-env.mjs';
|
|
11
12
|
import createTypes from '../utils/create-types.mjs';
|
|
12
13
|
import { generateDeclaration } from '../utils/dts.mjs';
|
|
@@ -15,11 +16,13 @@ import getCoverage from './coverage.mjs';
|
|
|
15
16
|
import { docs, docsModuleName } from './docs.mjs';
|
|
16
17
|
import info from './info.mjs';
|
|
17
18
|
import { locales, localesModuleName } from './locales.mjs';
|
|
19
|
+
import renderApp from './render-app.mjs';
|
|
18
20
|
import { route, routesModuleName } from './routes.mjs';
|
|
19
21
|
declare const mdxScope: string | false;
|
|
20
22
|
declare const normalModules: Record<string, string>;
|
|
21
23
|
declare const appDtsPath: string;
|
|
22
24
|
declare const appDts: string[];
|
|
23
25
|
declare const vmDtsPath: string;
|
|
26
|
+
declare const virtualModule: VirtualModulePluginOption;
|
|
24
27
|
declare const customVirtualModuleDts: string[];
|
|
25
28
|
export default normalModules;
|
package/lib/vm/modules.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join as
|
|
1
|
+
import{join as m}from"node:path";import{getAppEntry as o,getAppFallback as p,getAppMdxScope as e,getAppMergeRouter as t,getAppNormalizeCss as r,getAppPrefixRouter as s,getAppRem as a,getAppSuspense as i}from"@moneko/mdx";import{updateFileSync as n}from"@moneko/utils";import f from"../commom/has-pkg.mjs";import l from"../commom/parse-module-meta.mjs";import d from"../commom/paths.mjs";import c from"../commom/rule.mjs";import{CONFIG as x}from"../config.mjs";import u from"../plugin/module-federation.mjs";import{APPTYPE as j,FRAMEWORK as g}from"../process-env.mjs";import y from"../utils/create-types.mjs";import{generateDeclaration as v}from"../utils/dts.mjs";import{node_modules as h}from"../utils/index.mjs";import k from"./coverage.mjs";import{docs as O,docsModuleName as S}from"./docs.mjs";import b from"./info.mjs";import{locales as z,localesModuleName as D}from"./locales.mjs";import J from"./render-app.mjs";import{route as N,routesModuleName as $}from"./routes.mjs";let C=f(m(x.alias["@"],"./mdx-scope.tsx"))||f(m(x.alias["@"],"./mdx-scope.ts")),P={"@app/env.ts":`export default ${JSON.stringify(x.env)}`,"@app/info.ts":`export default ${JSON.stringify(b)}`,"@app/render.tsx":"react"===g?J:"","@app/entry.ts":o(m(x.alias["@"],"./index.ts"),!!u.length,!!x.rem,!!x.normalizeCss,j,g),"@app/rem":a(x.rem?.designSize||1680),"@app/fallback":p(x.fallbackCompPath),"@app/coverage":k(d.coveragePath),"@app/merge-router":t(),"@app/prefix-router":s(),"@app/normalize/index.css":r(),"@app/suspense/index.tsx":i(j,g),"@app/mdx-scope.tsx":C?e(C):"export default {}","@app/routes":N.getData($),"@app/locales":z.getData(D),"@app/docs":O.getData(S)};n(h("@types/@app/index.d.ts"),["@app/env.ts","@app/info.ts","@app/entry.ts","@app/mdx-scope.tsx"].map(m=>y(m.replace(c.js,""),v(P[m],m))).join("\n"));let M=h("@types/@vm/index.d.ts"),q=x.virtualModule||{};n(M,Object.keys(q).map(m=>{let o=q[m],{file:p}=l(m);return y(m,v("string"==typeof o?o:`export default ${JSON.stringify(o)}`,p))}).join("\n"));export default P;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CONFIG } from '../config.mjs';
|
|
2
|
+
import { APPTYPE, frameworkVersion, isDev, SSR } from '../process-env.mjs';
|
|
3
|
+
declare const ReactDomPath: string;
|
|
4
|
+
declare const isHashRouter: boolean;
|
|
5
|
+
declare const v7Future: Record<string, boolean | undefined>;
|
|
6
|
+
declare const createRouter: string;
|
|
7
|
+
declare const renderApp: string;
|
|
8
|
+
export default renderApp;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import{CONFIG as e}from"../config.mjs";import{APPTYPE as r,frameworkVersion as t,isDev as a,SSR as n}from"../process-env.mjs";let o="hash"===e.routerMode,s=Object.assign({v7_relativeSplatPath:!1},"browser"===e.routerMode?{v7_fetcherPersist:!1,v7_normalizeFormMethod:!1,v7_partialHydration:n,v7_skipActionErrorRevalidation:!1}:{}),c=o?"createHashRouter":"createBrowserRouter",i=`import React, { StrictMode, useRef, type ReactElement } from 'react';
|
|
2
|
+
import Fallback from '@app/fallback';
|
|
3
|
+
import routes from '@app/routes';
|
|
4
|
+
import ReactDOM from '${t<18?"react-dom":"react-dom/client"}';
|
|
5
|
+
import { RouterProvider, ${c} } from 'react-router-dom';
|
|
6
|
+
|
|
7
|
+
type RenderAppProps = {
|
|
8
|
+
container?: HTMLElement;
|
|
9
|
+
basename?: string;
|
|
10
|
+
fallback?: ReactElement;
|
|
11
|
+
language?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function App(props: RenderAppProps) {
|
|
15
|
+
const v7Future = useRef(${JSON.stringify(s)});
|
|
16
|
+
return (
|
|
17
|
+
<StrictMode>
|
|
18
|
+
<RouterProvider
|
|
19
|
+
router={${c}(routes, {
|
|
20
|
+
basename: ${o?"/":"props.basename"},
|
|
21
|
+
window: window,
|
|
22
|
+
future: v7Future.current,
|
|
23
|
+
})}
|
|
24
|
+
future={{
|
|
25
|
+
/** 这使用 useTransition 而不是 useState 来更新路由器状态 */
|
|
26
|
+
v7_startTransition: false,
|
|
27
|
+
}}
|
|
28
|
+
fallbackElement={Fallback && <Fallback />}
|
|
29
|
+
/>
|
|
30
|
+
</StrictMode>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function renderApp(props: RenderAppProps = {}) {
|
|
35
|
+
const { container, basename = "${e.basename}", language, ...args } = props;
|
|
36
|
+
const _container = container?.querySelector('#root') || document.getElementById('root');
|
|
37
|
+
${"micro"===r?"window.mainApp = { ...args, container: _container as HTMLElement };":""}
|
|
38
|
+
${t<18?`ReactDOM.${a?"render":"hydrate"}(<App basename={basename} language={language} />, _container);return () => ReactDOM.unmountComponentAtNode(_container as Element);`:"const instance = ReactDOM.createRoot(_container as HTMLElement);instance.render(<App basename={basename} language={language} />);return instance.unmount;"}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default renderApp;`;export default i;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneko/core",
|
|
3
|
-
"version": "3.27.
|
|
3
|
+
"version": "3.27.6-beta.1",
|
|
4
4
|
"description": "core",
|
|
5
5
|
"main": "lib/index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@types/webpack-bundle-analyzer": "4.7.0",
|
|
50
50
|
"@types/webpack-hot-middleware": "2.25.9",
|
|
51
51
|
"eslint-config-neko": "3.0.3",
|
|
52
|
-
"sass": "1.83.
|
|
52
|
+
"sass": "1.83.1",
|
|
53
53
|
"sass-loader": "16.0.4",
|
|
54
54
|
"solid-refresh": "0.7.5",
|
|
55
55
|
"stylis": "4.3.4",
|
package/typings/global.d.ts
CHANGED
|
@@ -20,9 +20,9 @@ import type {
|
|
|
20
20
|
OverrideResolverOption,
|
|
21
21
|
ProxyConfig,
|
|
22
22
|
VirtualModulePluginOption,
|
|
23
|
-
} from '../lib/index';
|
|
23
|
+
} from '../lib/index.mjs';
|
|
24
24
|
import type { CopyPluginOption } from '../lib/plugin/copy.mjs';
|
|
25
|
-
import type { DonePluginOption } from '../lib/plugin/done';
|
|
25
|
+
import type { DonePluginOption } from '../lib/plugin/done.mjs';
|
|
26
26
|
|
|
27
27
|
import type { BundleAnalyzerOption } from './bundle-analyzer.d';
|
|
28
28
|
|