@moneko/core 3.17.39 → 3.17.41

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,7 +1,4 @@
1
1
  import webpack from 'webpack';
2
2
  export declare const PORT: number;
3
3
  export declare function devLog(err?: Error | null, stats?: webpack.Stats): void;
4
- export declare const headers: {
5
- 'Access-Control-Allow-Origin': string;
6
- 'Access-Control-Allow-Headers': string;
7
- };
4
+ export declare const headers: {};
@@ -1,3 +1,3 @@
1
- import e from"chalk";import{getIPv4 as o,getPort as t}from"./net.mjs";import{CONFIG as r}from"../config.mjs";import s from"../utils/log.mjs";let{yellow:i,green:n,grey:l,gray:c,bgBlue:m,bgGreenBright:a,blueBright:p,greenBright:d}=e,$=r.devServer.port||3e3;export const PORT=await t($,r.devServer.host);r.devServer.port=PORT;let u="/"===r.basename?"":r.basename,v=$!==PORT&&c(`Port ${i($)} is in use, trying ${n(PORT)} instead.
2
- `);function f(e){return`http://${"local"===e?r.devServer.host:o()}:${PORT}${u}`}let T=c("You application is running here:"),g=`${m(" Local ")} ${p(f("local"))}
3
- ${a(" Network ")} ${d(f("net"))}`;export function devLog(e,o){!e&&o&&(process.stdout.write("\x1b[2J\x1b[3J\x1b[H"),s([T,"",g,"",l(`Compiled successfully in ${n(`${o.endTime-o.startTime}ms`)}`)]),v&&s(v))}export const headers={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Headers":"*"};
1
+ import e from"chalk";import{getIPv4 as t,getPort as o}from"./net.mjs";import{CONFIG as r}from"../config.mjs";import s from"../utils/log.mjs";let{yellow:i,green:n,grey:m,gray:a,bgBlue:l,bgGreenBright:p,blueBright:c,greenBright:$}=e,d=r.devServer.port||3e3;export const PORT=await o(d,r.devServer.host);r.devServer.port=PORT;let u="/"===r.basename?"":r.basename,v=d!==PORT&&a(`Port ${i(d)} is in use, trying ${n(PORT)} instead.
2
+ `);function f(e){return`http://${"local"===e?r.devServer.host:t()}:${PORT}${u}`}let T=a("You application is running here:"),h=`${l(" Local ")} ${c(f("local"))}
3
+ ${p(" Network ")} ${$(f("net"))}`;export function devLog(e,t){!e&&t&&(process.stdout.write("\x1b[2J\x1b[3J\x1b[H"),s([T,"",h,"",m(`Compiled successfully in ${n(`${t.endTime-t.startTime}ms`)}`)]),v&&s(v))}export const headers={};
package/lib/dev/proxy.mjs CHANGED
@@ -1 +1 @@
1
- import{createProxyMiddleware as e}from"http-proxy-middleware";export default((t,l)=>{let o=Object.keys(l);for(let r=0,p=o.length;r<p;r++){let p=o[r],d=e({logger:console,...l[p]});t.use(p,d)}});
1
+ import{createProxyMiddleware as e}from"http-proxy-middleware";export default((t,r)=>{let l=Object.keys(r);for(let o=0,g=l.length;o<g;o++){let g=l[o],i=e({logger:!1,changeOrigin:!0,...r[g]});t.use(g,i)}});
package/lib/dev.mjs CHANGED
@@ -1 +1 @@
1
- import e from"express";import t from"multer";import o from"webpack";import i from"webpack-dev-middleware";import s from"webpack-hot-middleware";import{merge as r}from"webpack-merge";import l from"./build/server.mjs";import{commonConfig as n}from"./common.mjs";import{CONFIG as m,PUBLICPATH as a}from"./config.mjs";import{PORT as c,devLog as p,headers as u}from"./dev/config.mjs";import f from"./dev/mock.mjs";import d from"./dev/proxy.mjs";import h from"./module.config.mjs";import g,{CUSTOMCONFIG as w}from"./paths.mjs";import{SSR as x,isLibrary as j,isReact as $}from"./process-env.mjs";import k from"./utils/has-pkg.mjs";import{empty as y,resolveProgram as b}from"./utils/index.mjs";import P from"./utils/progress.mjs";import v from"./utils/sigint-exit.mjs";import C from"./options/reslove.mjs";import{watchFile as T}from"fs";import{spawn as S,exec as A}from"child_process";import D from"./utils/log.mjs";import E from"chalk";import{directoryExists as M,loadFileSync as _,removeDir as H}from"@moneko/utils";import I from"cors";let{HotModuleReplacementPlugin:O,ProgressPlugin:U,WatchIgnorePlugin:B}=o,G=k("stylelint-webpack-plugin")&&(await import("stylelint-webpack-plugin")).default,L=k("eslint-webpack-plugin")&&(await import("eslint-webpack-plugin")).default,R=$&&(await import("@pmmmwh/react-refresh-webpack-plugin")).default,q=["js","jsx","ts","tsx","json","html","vue"],N=q.join(","),W=["css","scss","sass","less","ts","tsx","js","jsx"],F=W.join(","),X=["node_modules/","es/","lib/","umd/","docs/","coverage/","dist/"],z=k("solid-refresh")||k("react-refresh"),K=`${a.endsWith("/")?"":"/"}__hmr__`,J=new URLSearchParams({name:"client",path:K,dynamicPublicPath:!0,timeout:2e3,reload:!z,quiet:!0,noInfo:!0,overlay:!0}).toString(),Q=n.output.path;x&&(Q=b(`${j?"docs":"dist"}/client`));let V=!!m.bar,Y=r(n,{entry:{main:[`${C.hotMiddlewareClient}?${J}`]},output:{path:Q},module:h(!1),plugins:[new O,new B({paths:[/\.d\.ts$/]}),R&&new R,L&&new L({fix:!0,threads:!0,files:[`${m.alias["@"]}/**/*.{${N}}`,j&&`${m.alias["@pkg"]}/**/*.{${N}}`].filter(Boolean),extensions:q,exclude:X,cache:!0,cacheLocation:`${g.lineCachePath}/.eslintcache`,lintDirtyModulesOnly:!0}),G&&new G({fix:!0,threads:!0,files:[`${m.alias["@"]}/**/*.{${F}}`,j&&`${m.alias["@pkg"]}/**/*.{${F}}`].filter(Boolean),extensions:W,exclude:X,cache:!0,cacheLocation:`${g.lineCachePath}/.stylelintcache`,lintDirtyModulesOnly:!0}),new U({handler(e,t,...o){let i=m.bar||{};P({showBar:V,percentage:e,title:i.name||"Build",color:i.color,info:o.length?`[${t}] ${o.join(" ")}`:"",output:Y.output?.path})}})].filter(Boolean)}),Z=[Y];x&&Z.push(r(n,l));let ee=o(Z);ee.compilers[0].hooks.done.tap("client-log",e=>{p(null,e)});let et=e(),eo=I({origin:!0,preflightContinue:!0,credentials:!0,allowedHeaders:["DNT","X-Mx-ReqToken","Keep-Alive","User-Agent","X-Requested-With","If-Modified-Since","Cache-Control","Content-Type","Authorization"],methods:["GET","HEAD","PUT","PATCH","POST","DELETE","OPTIONS"]});et.use(eo),et.options("*",eo);let ei=t(),es=i(ee,{writeToDisk:!1,index:"index.html",headers:u,serverSideRender:x,lastModified:!0}),er=s(ee,{log:!1,path:K,heartbeat:2e3});if(et.use(es),et.use(er),et.use(e.static(Y.output.path)),m.proxy&&d(et,m.proxy),M(g.mockPath)){let e=f(g.mockPath);et.use(e)}let el=`${Y.output.path}/index.html`;et.all("/*",ei.any(),function(e,t,o){if("GET"!==e.method)return o();{let i=e.get("Accept");if(i?.includes("text/html")){let e=es.context.outputFileSystem,o=e?.readFileSync?.(el);t.end(o)}else if("text/event-stream"===i&&e.url.endsWith(K))return e.url=K,er(e,t,o);else return o()}});let en=et.listen(c,()=>{});function em(){process.exit(0)}function ea(e,t){let o=_(e);t&&null!==o&&T(e,async function(){let i=_(e);o.trim().replace(/^\s*[\r\n]/gm,"")!==i?.trim().replace(/^\s*[\r\n]/gm,"")?(D(E.yellow(`检测到工程配置${E.blue(`[${t}]`)}变更, 程序即将重启...`)),A("win32"===process.platform?`netstat -ano | findstr :${c}`:`lsof -i :${c}`,(e,t,o)=>{let i=ec?t.split(/\s+/).pop():t.split("\n")[1]?.split(/\s+/)[1];i?process.kill(Number(i),"SIGHUP"):D(`未找到占用端口 ${c} 的进程`)})):D(E.gray(`未变更`))})}ea(g.configPath,"index"),ea(g.customConfigPath,w);let ec="win32"===process.platform;process.on("SIGHUP",function(){es.close(y),en.close(y),en.closeAllConnections(),function(){let e=S(process.argv[0],process.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",em)}()}),process.on("exit",function(){es.close(y),en.close(y),en.closeAllConnections(),H(g.cachePath)}),v(em);
1
+ import e from"express";import t from"multer";import o from"webpack";import i from"webpack-dev-middleware";import s from"webpack-hot-middleware";import{merge as l}from"webpack-merge";import r from"./build/server.mjs";import{commonConfig as n}from"./common.mjs";import{CONFIG as m,PUBLICPATH as a}from"./config.mjs";import{PORT as c,devLog as p,headers as u}from"./dev/config.mjs";import f from"./dev/mock.mjs";import d from"./dev/proxy.mjs";import h from"./module.config.mjs";import g,{CUSTOMCONFIG as w}from"./paths.mjs";import{SSR as x,isLibrary as j,isReact as $}from"./process-env.mjs";import k from"./utils/has-pkg.mjs";import{empty as y,resolveProgram as b}from"./utils/index.mjs";import P from"./utils/progress.mjs";import v from"./utils/sigint-exit.mjs";import A from"./options/reslove.mjs";import{watchFile as C}from"fs";import{spawn as T,exec as S}from"child_process";import M from"./utils/log.mjs";import O from"chalk";import{directoryExists as _,loadFileSync as D,removeDir as E}from"@moneko/utils";let{HotModuleReplacementPlugin:I,ProgressPlugin:U,WatchIgnorePlugin:B}=o,G=k("stylelint-webpack-plugin")&&(await import("stylelint-webpack-plugin")).default,H=k("eslint-webpack-plugin")&&(await import("eslint-webpack-plugin")).default,L=$&&(await import("@pmmmwh/react-refresh-webpack-plugin")).default,R=["js","jsx","ts","tsx","json","html","vue"],q=R.join(","),N=["css","scss","sass","less","ts","tsx","js","jsx"],W=N.join(","),F=["node_modules/","es/","lib/","umd/","docs/","coverage/","dist/"],X=k("solid-refresh")||k("react-refresh"),z=`${a.endsWith("/")?"":"/"}__hmr__`,K=new URLSearchParams({name:"client",path:z,dynamicPublicPath:!0,timeout:2e3,reload:!X,quiet:!0,noInfo:!0,overlay:!0}).toString(),J=n.output.path;x&&(J=b(`${j?"docs":"dist"}/client`));let Q=!!m.bar,V=l(n,{entry:{main:[`${A.hotMiddlewareClient}?${K}`]},output:{path:J},module:h(!1),plugins:[new I,new B({paths:[/\.d\.ts$/]}),L&&new L,H&&new H({fix:!0,threads:!0,files:[`${m.alias["@"]}/**/*.{${q}}`,j&&`${m.alias["@pkg"]}/**/*.{${q}}`].filter(Boolean),extensions:R,exclude:F,cache:!0,cacheLocation:`${g.lineCachePath}/.eslintcache`,lintDirtyModulesOnly:!0}),G&&new G({fix:!0,threads:!0,files:[`${m.alias["@"]}/**/*.{${W}}`,j&&`${m.alias["@pkg"]}/**/*.{${W}}`].filter(Boolean),extensions:N,exclude:F,cache:!0,cacheLocation:`${g.lineCachePath}/.stylelintcache`,lintDirtyModulesOnly:!0}),new U({handler(e,t,...o){let i=m.bar||{};P({showBar:Q,percentage:e,title:i.name||"Build",color:i.color,info:o.length?`[${t}] ${o.join(" ")}`:"",output:V.output?.path})}})].filter(Boolean)}),Y=[V];x&&Y.push(l(n,r));let Z=o(Y);Z.compilers[0].hooks.done.tap("client-log",e=>{p(null,e)});let ee=e(),et=t(),eo=i(Z,{writeToDisk:!1,index:"index.html",headers:e=>({"Access-Control-Allow-Origin":e.headers.origin||"*","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",...u}),serverSideRender:x,lastModified:!0}),ei=s(Z,{log:!1,path:z,heartbeat:2e3});if(ee.use(eo),ee.use(ei),ee.use(e.static(V.output.path)),m.proxy&&d(ee,m.proxy),_(g.mockPath)){let e=f(g.mockPath);ee.use(e)}let es=`${V.output.path}/index.html`;ee.all("/*",et.any(),function(e,t,o){if("GET"!==e.method)return o();{let i=e.get("Accept");if(i?.includes("text/html")){let e=eo.context.outputFileSystem,o=e?.readFileSync?.(es);t.end(o)}else if("text/event-stream"===i&&e.url.endsWith(z))return e.url=z,ei(e,t,o);else return o()}});let el=ee.listen(c,()=>{});function er(){process.exit(0)}function en(e,t){let o=D(e);t&&null!==o&&C(e,async function(){let i=D(e);o.trim().replace(/^\s*[\r\n]/gm,"")!==i?.trim().replace(/^\s*[\r\n]/gm,"")?(M(O.yellow(`检测到工程配置${O.blue(`[${t}]`)}变更, 程序即将重启...`)),S("win32"===process.platform?`netstat -ano | findstr :${c}`:`lsof -i :${c}`,(e,t,o)=>{let i=em?t.split(/\s+/).pop():t.split("\n")[1]?.split(/\s+/)[1];i?process.kill(Number(i),"SIGHUP"):M(`未找到占用端口 ${c} 的进程`)})):M(O.gray(`未变更`))})}en(g.configPath,"index"),en(g.customConfigPath,w);let em="win32"===process.platform;process.on("SIGHUP",function(){eo.close(y),el.close(y),el.closeAllConnections(),function(){let e=T(process.argv[0],process.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",er)}()}),process.on("exit",function(){eo.close(y),el.close(y),el.closeAllConnections(),E(g.cachePath)}),v(er);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "3.17.39",
3
+ "version": "3.17.41",
4
4
  "description": "core",
5
5
  "main": "lib/index.mjs",
6
6
  "type": "module",
@@ -22,7 +22,6 @@
22
22
  "chokidar": "3.6.0",
23
23
  "core-js": "3.37.1",
24
24
  "core-js-compat": "3.37.1",
25
- "cors": "2.8.5",
26
25
  "css-loader": "7.1.2",
27
26
  "dotenv": "16.4.5",
28
27
  "express": "4.19.2",
@@ -51,7 +50,6 @@
51
50
  "@moneko/css": "1.1.5",
52
51
  "@swc/cli": "0.3.12",
53
52
  "@types/babel__core": "7.20.5",
54
- "@types/cors": "2.8.17",
55
53
  "@types/express": "4.17.21",
56
54
  "@types/multer": "1.4.11",
57
55
  "@types/webpack-bundle-analyzer": "4.7.0",
@@ -218,7 +218,24 @@ export declare type ConfigType = {
218
218
  cssModuleDefinition: boolean;
219
219
  /** 按需引入 */
220
220
  importOnDemand?: SwcImportOnDemandTransform;
221
- /** 开发服务器代理 */
221
+ /** 开发服务器代理
222
+ * @example
223
+ * ```js
224
+ * const conf: Partial<ConfigType> = {
225
+ * proxy: [
226
+ * // /api/user/admin -> http://1.2.3.4:8008/user/admin
227
+ * '/api/': {
228
+ * target: 'http://1.2.3.4:8008/',
229
+ * pathRewrite: { '^/api/': '/' },
230
+ * },
231
+ * // /bbs/2 -> http://1.2.3.4:9002/bbs/2
232
+ * '/bbs/': {
233
+ * target: 'http://1.2.3.4:9002/',
234
+ * },
235
+ * ],
236
+ * };
237
+ * ```
238
+ */
222
239
  proxy?: ProxyConfig;
223
240
  /**
224
241
  * 缓存配置