@empjs/cli 3.0.0-beta.27 → 3.0.0-beta.29

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,2 +0,0 @@
1
- declare let ep: any;
2
- export default ep;
@@ -1,14 +0,0 @@
1
- declare const _default: {
2
- path: string;
3
- timeout: number;
4
- overlay: boolean;
5
- reload: boolean;
6
- log: boolean;
7
- warn: boolean;
8
- name: string;
9
- autoConnect: boolean;
10
- overlayStyles: {};
11
- overlayWarnings: boolean;
12
- ansiColors: {};
13
- };
14
- export default _default;
@@ -1,6 +0,0 @@
1
- export declare const pathMatch: (url: string, path: string) => boolean;
2
- export default function webpackHotMiddleware(compiler: any, opts?: any): {
3
- (req: any, res: any, next: any): any;
4
- publish(payload: any): void;
5
- close(): void;
6
- };
@@ -1,6 +0,0 @@
1
- export declare function showProblems(type: any, lines: any): void;
2
- export declare function clear(): void;
3
- export default function (options: any): {
4
- showProblems: typeof showProblems;
5
- clear: typeof clear;
6
- };
@@ -1,3 +1,4 @@
1
+ export declare const getPkgVersion: (pkgPath: string) => any;
1
2
  export declare function clearConsole(): void;
2
3
  export declare function deepAssign<T>(target: any, ...sources: any): T;
3
4
  export declare const ensureArray: <T>(params: T | T[]) => T[];
@@ -10,3 +11,4 @@ export declare const ensureArray: <T>(params: T | T[]) => T[];
10
11
  export declare const jsonFilter: (d?: any, notIncludeKeys?: string[]) => any;
11
12
  export declare const vCompare: (preVersion?: string, lastVersion?: string) => number;
12
13
  export declare const timeFormat: (seconds: number) => string;
14
+ export declare const importJsVm: (content: string) => string;
package/dist/index.js CHANGED
@@ -1,15 +1,16 @@
1
- var pe=Object.defineProperty;var l=(r,t)=>()=>(r&&(t=r(r=0)),t);var B=(r,t)=>{for(var e in t)pe(r,e,{get:t[e],enumerable:!0})};import{fileURLToPath as ae}from"node:url";import{dirname as le}from"node:path";import{readFile as ce}from"node:fs/promises";import ht from"node:module";import G from"node:path";var ft,me,U,he,ut,gt,dt=l(()=>{"use strict";ft=ae(import.meta.url),me=le(ft),U=async r=>{try{let t=await ce(r);return JSON.parse(t)}catch(t){console.error(t)}},he=ht.createRequire(import.meta.url),ut=(r,t)=>{let e=he;return t&&(e=ht.createRequire(t)),e.resolve(r)},gt=G.resolve(me,ft).replace(`${G.sep}dist${G.sep}index.js`,"")});import E from"@rspack/core";import yt from"fs";var I,bt,vt=l(()=>{"use strict";I=class{store;async setup(t){this.store=t;let e=[this.define(),this.anylayze(),this.progress(),this.copy(),this.empShare(),this.minify()];await Promise.all(e)}async anylayze(){if(!this.store.cliOptions.analyze)return;let{default:{BundleAnalyzerPlugin:t}}=await import("webpack-bundle-analyzer");this.store.chain.plugin("bundleAnalyzerPlugin").use(t,[{}])}async define(){this.store.chain.plugin("definePlugin").use(E.DefinePlugin,[this.store.empConfig.define])}async copy(){let t=this.store.resolve("public");yt.existsSync(t)&&yt.readdirSync(t).length>0&&this.store.chain.plugin("copyRspackPlugin").use(E.CopyRspackPlugin,[{patterns:[{from:t,to:this.store.resolve("dist")}]}])}async progress(){this.store.empConfig.debug.progress&&this.store.chain.plugin("progressPlugin").use(E.ProgressPlugin,[{prefix:"EMP"}])}async empShare(){let{config:t,version:e}=this.store.empConfig.empShareLib;if(!t.name)return;let{ModuleFederationPluginV1:i,ModuleFederationPlugin:o}=E.container,p=e===1?i:o;this.store.chain.plugin("empShare").use(p,[this.store.empConfig.empShareLib.pluginConfig])}minify(){this.store.chain.optimization.minimize(this.store.mode==="production"),this.store.chain.optimization.minimizer("minJs").use(E.SwcJsMinimizerRspackPlugin,[this.store.empConfig.build.minOptions]),this.store.chain.optimization.minimizer("minCss").use(E.SwcCssMinimizerRspackPlugin,[{}])}},bt=new I});var H,Ct,wt=l(()=>{"use strict";H=class{store;async setup(t){this.store=t;let e=[this.react(),this.files(),this.scripts()];await Promise.all(e)}async scripts(){let{isDev:t}=this.store,e=this.store.reactVersion?{react:{runtime:this.store.empConfig.reactRuntime,development:t,refresh:t}}:{};this.store.chain.merge({module:{parser:{javascript:{exportsPresence:"error",importExportsPresence:"error"}},rule:{mjs:{test:/\.m?js/,resolve:{fullySpecified:!1}},typescript:{test:/\.(ts|tsx)$/,sideEffects:!1,use:[{loader:"builtin:swc-loader",options:{jsc:{target:this.store.empConfig.build.target,parser:{syntax:"typescript",decorators:!0,tsx:!0,dynamicImport:!0},transform:e}}}]},javascript:{test:/\.(js|jsx)$/,sideEffects:!1,use:[{loader:"builtin:swc-loader",options:{jsc:{target:this.store.empConfig.build.target,parser:{syntax:"ecmascript",jsx:!0,decorators:!0,decoratorsBeforeExport:!1},transform:e}}}]}}}})}async react(){if(this.store.reactVersion&&(this.store.empConfig.react.svgr&&this.store.chain.merge({module:{rule:{svg:{test:/\.svg$/,issuer:/\.[jt]sx?$/,resourceQuery:/svgr/,use:[{loader:this.store.importResolve("@svgr/webpack"),options:{}}]}}}}),this.store.isDev&&this.store.empConfig.react.hmr)){let{default:t}=await import("@rspack/plugin-react-refresh"),e={};this.store.empConfig.empShareLib.config.name&&(e.library=this.store.empConfig.empShareLib.config.name),this.store.chain.plugin("plugin-react-refresh").use(t,[e])}}async files(){(!this.store.reactVersion||!this.store.empConfig.react.svgr)&&this.store.chain.merge({module:{rule:{svg:{test:/\.svg$/,type:"asset/resource"}}}}),this.store.chain.merge({module:{rule:{inline:{resourceQuery:/inline/,type:"asset/inline"}}}}),this.store.chain.merge({module:{rule:{image:{test:/\.(png|jpe?g|gif|webp|ico)$/i,type:"asset/resource"},fonts:{test:/\.(|otf|ttf|eot|woff|woff2)$/i,type:"asset/resource"},svga:{test:/\.(svga)$/i,type:"asset/resource"}}}})}},Ct=new H});var N,xt,St=l(()=>{"use strict";N=class{store;async setup(t){this.store=t;let e=[this.common(),this.stats(),this.devServer(),this.optimization()];await Promise.all(e)}async common(){this.store.merge({experiments:{rspackFuture:{},outputModule:this.store.empConfig.isESM,topLevelAwait:!0},target:this.store.empConfig.target,infrastructureLogging:this.store.empConfig.debug.infrastructureLogging,context:this.store.root,mode:this.store.mode,cache:!0,devtool:this.store.empConfig.build.sourcemap?"source-map":!1,builtins:{css:{modules:{localIdentName:this.store.isDev?"[path][name]-[local]-[hash:5]":"[local]-[hash:5]"}}},output:this.store.empConfig.output,resolve:this.store.empConfig.resolve,externals:this.store.empConfig.externals})}async stats(){this.store.merge({stats:{colors:!0,all:!1,assets:!1,chunks:!1,timings:!0,version:!0}})}async devServer(){this.store.merge({devServer:this.store.empConfig.server})}async optimization(){this.store.chain.merge({optimization:{chunkIds:this.store.empConfig.build.chunkIds,minimize:this.store.empConfig.build.minify}})}},xt=new N});import fe from"chalk";function Et(){process.stdout.write(process.platform==="win32"?"\x1B[2J\x1B[0f":"\x1B[2J\x1B[3J\x1B[H")}function g(r,...t){for(let e of t)for(let s in e){let i=e[s],o=r[s];if(Object(i)==i&&Object(o)===o){r[s]=g(o,i);continue}r[s]=e[s]}return r}var R,Ot,y=l(()=>{"use strict";R=(r="",t="")=>{let e=r.replace("^","").split("."),s=t.replace("^","").split("."),i=Math.max(e.length,s.length),o=0;for(let p=0;p<i;p++){let c=e.length>p?e[p]:0,h=isNaN(Number(c))?c.charCodeAt():Number(c),$=s.length>p?s[p]:0,m=isNaN(Number($))?$.charCodeAt():Number($);if(h<m){o=-1;break}else if(h>m){o=1;break}}return o},Ot=r=>{r=r/1e3;let t=s=>fe.bold(s);if(r<1)return`${r*1e3} ms`;if(r<10){let s=r>=.01?2:3;return`${t(r.toFixed(s))} s`}if(r<60)return`${t(r.toFixed(1))} s`;let e=r/60;return`${t(e.toFixed(2))} m`}});import $t from"html-webpack-plugin";import ue from"fast-glob";import x from"node:path";var _,V,Pt,kt=l(()=>{"use strict";y();_=class{importMap;constructor(t){this.importMap=t}apply(t){t.hooks.compilation.tap("HtmlImportMapPlugin",e=>{$t.getHooks(e).alterAssetTagGroups.tapAsync("HtmlImportMapPlugin",(s,i)=>{s.headTags.push({tagName:"script",attributes:{type:"importmap"},innerHTML:`${JSON.stringify(this.importMap,null,2)}`,voidTag:!1,meta:{plugin:void 0}}),i(null,s)})})}},V=class{store;entriesConfig={};async setup(t){this.store=t,await this.init(),this.toConfig()}setHtmlConfig(t,e){return t.template=this.setTemplate(t.template),t.favicon=this.setFavicion(t.favicon),t.chunks=e,t.filename=`${e[0]}.html`,this.store.empConfig.base&&(t.publicPath=this.store.empConfig.base),this.store.empConfig.empShareLib&&(t.files=g(t.files,this.store.empConfig.empShareLib.externalAssets)),t.tags=t.tags||{},t}setChunk(t){return t.replace(x.extname(t),"").replace(`${this.store.empConfig.appSrc}${x.sep}`,"")}setTemplate(t){return t?this.store.resolve(t):this.store.empResolve(x.join("template","index.html"))}setFavicion(t){return t?this.store.resolve(t):this.store.empResolve(x.join("template","favicon.ico"))}setEntryItem(t,e,s){s=s||this.store.resolve(x.join(this.store.empConfig.appSrc,t));let i=this.setChunk(t);this.entriesConfig[i]={entry:{[i]:s},html:this.setHtmlConfig(e,[i])}}setRspackHtmlPlugin(t,e){this.store.chain.plugin(`html-plugin-${e}`).use($t,[t]),this.store.empConfig.empShareLib.useImportMap&&this.store.chain.plugin(`html-plugin-import-map-${e}`).use(_,[this.store.empConfig.empShareLib.importMap])}setRspackEntry(t){this.store.merge({entry:t})}async init(){let t=x.join(this.store.appSrc,this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index.{ts,tsx,jsx,js}").replace(/\\/g,"/"),e=await ue([t]);if(e[0]){let s=x.join(this.store.empConfig.appSrc,Object.keys(this.store.empConfig.entries).length>0&&this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index");this.setEntryItem(s,this.store.empConfig.html,e[0])}if(Object.keys(this.store.empConfig.entries).length>0)for(let[s,i]of Object.entries(this.store.empConfig.entries))this.setEntryItem(s,{...this.store.empConfig.html,...i})}toConfig(){for(let[t,e]of Object.entries(this.entriesConfig))this.setRspackHtmlPlugin(e.html,t),this.setRspackEntry(e.entry)}},Pt=new V});var J,Rt,Lt=l(()=>{"use strict";J=class{store;async setup(t){this.store=t;let e=[this.sass(),this.less(),this.css()];await Promise.all(e)}async sass(){let t={loader:this.store.importResolve("sass-loader"),options:{}};this.store.chain.merge({module:{rule:{sass:{test:/\.(sass|scss)$/,use:{postcss:this.postcss,sassLoader:t},type:"css/auto"}}}})}async less(){let t={loader:this.store.importResolve("less-loader"),options:{lessOptions:{javascriptEnabled:!0}}};this.store.chain.merge({module:{rule:{less:{test:/\.less$/,use:{postcss:this.postcss,lessLoader:t},type:"css/auto"}}}})}async css(){this.store.chain.merge({module:{rule:{css:{test:/\.css$/,use:{postcss:this.postcss},type:"css/auto"}}}})}get postcss(){return{loader:this.store.importResolve("postcss-loader"),options:{postcssOptions:{plugins:this.store.empConfig.css.postcss}}}}},Rt=new J});var W,jt,Tt=l(()=>{"use strict";vt();wt();St();kt();Lt();W=class{store;async setup(t){this.store=t;let e=[xt.setup(this.store),Ct.setup(this.store),bt.setup(this.store),Pt.setup(this.store),Rt.setup(this.store)];await Promise.all(e),await this.store.empConfig.plugins(),await this.store.empConfig.chain()}},jt=new W});import f from"chalk";import{table as ge}from"table";var X,a,b=l(()=>{"use strict";X=class{pname="";logLevel="debug";setup({pname:t,logLevel:e}){this.pname=t,e&&(this.logLevel=e)}debug=(...t)=>["debug"].includes(this.logLevel)&&console.log(...t);info=(...t)=>["debug","info"].includes(this.logLevel)&&console.log(...t);warn=(...t)=>["debug","info","warn"].includes(this.logLevel)&&console.warn(...t);error=(...t)=>["debug","info","warn","error"].includes(this.logLevel)&&console.error(...t);blue=t=>{console.log(`${f.white.bgBlue(this.pname)}${f.blue.bgWhite(` ${t} `)}
2
- `)};cyan=t=>{console.log(`${f.white.bgCyan(this.pname)}${f.cyan.bgWhite(` ${t} `)}
3
- `)};magenta=t=>{console.log(`${f.white.bgMagenta(this.pname)}${f.magenta.bgWhite(` ${t} `)}
4
- `)};green=t=>{console.log(`${f.white.bgGreen(this.pname)}${f.green.bgWhite(` ${t} `)}
5
- `)};yellow=t=>{console.log(`${f.white.bgYellow(this.pname)}${f.yellow.bgWhite(` ${t} `)}
6
- `)};red=t=>{console.log(`${f.white.bgRed(this.pname)}${f.red.bgWhite(` ${t} `)}
7
- `)};sysError=t=>{console.log(`${f.white.bgRed(" System Error Tips ")}${f.red.bgWhite(` ${t} `)}
8
- `)};link=t=>f.hex("#3498db")(t);title=t=>{console.log(`${f.greenBright.bold(`${this.pname}`)} ${f.bgGreenBright(` ${t} `)}
9
- `)};tableData=[];tableConfig={border:{topBody:"\u2500",topJoin:"\u252C",topLeft:"\u250C",topRight:"\u2510",bottomBody:"\u2500",bottomJoin:"\u2534",bottomLeft:"\u2514",bottomRight:"\u2518",bodyLeft:"\u2502",bodyRight:"\u2502",bodyJoin:"\u2502",joinBody:"\u2500",joinLeft:"\u251C",joinRight:"\u2524",joinJoin:"\u253C"}};tableInput(t){this.tableData.push(t)}tableOutput(){console.log(ge(this.tableData,this.tableConfig))}},a=new X});var L,Dt=l(()=>{"use strict";d();L=class{externals={};externalAssets={js:[],css:[]};exp=/^([0-9a-zA-Z_\s]+)@(.*)/;config;importMap={imports:{}};version;async setup(){this.config=n.empConfig.empShare,this.version=n.empConfig.empShare.mfVersion,this.config.shareLib&&this.setShareLib(),this.prepareEsm()}get useImportMap(){return this.config.useImportMap&&n.empConfig.isESM}get pluginConfig(){let t={...this.config};return delete t.mfVersion,delete t.shareLib,delete t.useImportMap,t}prepareEsm(){if(n.empConfig.isESM){this.config.library={type:"module"};let t=this.config.remotes||{};for(let[e,s]of Object.entries(t))if(typeof s=="string"){let i=s.match(this.exp)||[];i.length>0&&(t[e]=i[2])}this.config.remotes=t}}async setShareLib(){let t=this.config,e=[];if(typeof t.shareLib=="object")for(let[s,i]of Object.entries(t.shareLib)){let o={};if(o.module=s,typeof i=="string"){let p=i.match(this.exp)||[];p.length>0?(o.global=p[1],o.entry=p[2],o.type="js",e.push(o),o={}):(o.global="",o.entry=i,o.type="js",e.push(o),o={})}else Array.isArray(i)?i.map(p=>{if(!p)return;if(p.split("?")[0].endsWith(".css"))o.entry=p,o.type="css";else{let h=p.match(this.exp)||[];h.length>0?(o.global=h[1],o.entry=h[2],o.type="js"):(o.global="",o.entry=p,o.type="js")}e.push(o),o={}}):typeof i=="object"&&i.entry&&(o.entry=i.entry,o.global=i.global,o.type=i.type,e.push(o),o={})}await Promise.all([this.setExternalAssets(e)])}async setExternalAssets(t=[]){if(t.length>0){let e=[];e=e.concat(t),e.map(s=>{s.type=s.type||"js",s.type==="js"&&s.module?(s.global?this.externals[s.module]=s.global:n.empConfig.isESM&&(this.useImportMap?(this.externals[s.module]=s.module,this.importMap.imports[s.module]=s.entry):this.externals[s.module]=s.entry),s.entry&&!n.empConfig.isESM&&this.externalAssets.js.push(s.entry)):s.type==="css"&&s.entry&&this.externalAssets.css.push(s.entry)})}}}});import Ft from"url";import Mt from"chalk";import{ip as de}from"address";import{gateway4sync as ye}from"default-gateway";var q,O,Q=l(()=>{"use strict";q=class{imf={protocol:"",port:8e3,pathname:"/"};host="0.0.0.0";urls={lanUrlForConfig:"",lanUrlForTerminal:Mt.gray("unavailable"),localUrlForTerminal:"",localUrlForBrowser:""};setup(t){t.host&&(this.host=t.host),t.protocol&&(this.imf.protocol=t.protocol),t.pathname&&(this.imf.pathname=t.pathname),t.port&&(this.imf.port=t.port),this.setupUrls()}setupUrls(){let{host:t}=this,e=t==="0.0.0.0"||t==="::",s;if(e){s="localhost";try{this.urls.lanUrlForConfig=this.getLanIp(),this.urls.lanUrlForConfig&&(/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(this.urls.lanUrlForConfig)?this.urls.lanUrlForTerminal=this.prettyPrintUrl(this.urls.lanUrlForConfig):this.urls.lanUrlForConfig="")}catch{}}else s=t,this.urls.lanUrlForConfig=t,this.urls.lanUrlForTerminal=this.prettyPrintUrl(this.urls.lanUrlForConfig);this.urls.localUrlForTerminal=this.prettyPrintUrl(s),this.urls.localUrlForBrowser=this.formatUrl(s)}getLanIp(){let{int:t}=ye();return de(t||"")||"127.0.0.1"}formatUrl(t){let{protocol:e,port:s,pathname:i}=this.imf;return Ft.format({protocol:e,hostname:t,port:s,pathname:i})}prettyPrintUrl(t){let{protocol:e,port:s,pathname:i}=this.imf;return Ft.format({protocol:e,hostname:t,port:Mt.bold(s),pathname:i})}},O=new q});var Y,j,Z=l(()=>{"use strict";Q();y();d();Y=class{isADB=!1;isHttps=!1;get isHttpBase(){let t=n.empOptions.base||"";return t.indexOf("http://")>-1||t.indexOf("https://")>-1}setup(){if(this.isADB=!!n.empOptions.autoDevBase&&n.mode==="development"&&!this.isHttpBase,!this.isADB)return;let{server:t,https:e}=n.empOptions.server||{};this.isHttps=t==="https"||typeof t=="object"&&t.type==="https"||e===!0;let s=O.getLanIp(),i=this.isHttps?"https":"http",o=n.empOptions.server?.port||8e3;n.empOptions.base=`${i}://${s}:${o}/`,n.empOptions.server=g({port:o,client:{webSocketURL:`${this.isHttps?"wss":"ws"}://${s}:${o}/ws`}},n.empOptions.server)}},j=new Y});var K,At,zt=l(()=>{"use strict";Z();K=class{async afterGetEmpOptions(){j.setup()}},At=new K});import be from"node:fs";var tt,Bt,Gt=l(()=>{"use strict";y();Dt();zt();tt=class{store;appSrc="src";appEntry="";base="";target=[];assign(t,e){return e=e||{},g(t,e)}empShareLib=new L;isESM=!1;async autoDevSet(){this.store.mode==="development"&&this.store.empOptions.autoDevBase}checkIsESM(t){return["es3","es5"].indexOf(t)===-1}async setup(t){this.store=t,await this.syncEmpOptions(),await At.afterGetEmpOptions(),this.isESM=this.checkIsESM(this.build.target),this.store.empOptions.target?(this.target=this.store.empOptions.target,Array.isArray(this.target)&&!this.target.includes(this.build.target)&&this.target.push(this.build.target)):this.target=["web",this.build.target];let{appSrc:e,base:s,appEntry:i}=this.store.empOptions;e&&(this.appSrc=e),s&&(this.base=s),i&&(this.appEntry=i),this.store.empConfig.empShare&&await this.empShareLib.setup()}async chain(){this.store.empOptions.chain&&await this.store.empOptions.chain(this.store.chain)}async plugins(){let t=[];this.store.empOptions.plugins&&Array.isArray(this.store.empOptions.plugins)&&this.store.empOptions.plugins.length>0&&(this.store.empOptions.plugins.map(e=>{t.push(e.rsConfig(this.store))}),await Promise.all(t))}get debug(){return this.assign({loggerLevel:"info",clearLog:!0,progress:!0,showRsconfig:!1,infrastructureLogging:{appendOnly:!0,level:"warn"}},this.store.empOptions.debug)}get build(){let t=this.store.empOptions.build?.staticDir?`${this.store.empOptions.build?.staticDir}/`:"";return this.assign({outDir:"dist",staticDir:t,assetsDir:"assets",publicDir:"public",chunkIds:this.store.isDev?"named":"deterministic",sourcemap:!0,minify:!this.store.isDev,minOptions:{},target:"es5"},{...this.store.empOptions.build,staticDir:t})}get html(){let t=this.store.empOptions.html?.template?[]:{charset:{charset:"utf-8"},"http-equiv":{"http-equiv":"X-UA-Compatible",content:"IE=edge"},viewport:{content:"width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"}};return this.assign({lang:"zh-CN",title:"EMP",inject:"body",minify:!this.store.isDev,scriptLoading:this.isESM?"module":"defer",meta:t,files:{css:[],js:[]},tags:{headTags:[],bodyTags:[]}},this.store.empOptions.html)}get entries(){return this.store.empOptions.entries?this.store.empOptions.entries:{}}get react(){return this.assign({hmr:!0,svgr:!1},this.store.empOptions.react)}get server(){let t={host:"0.0.0.0",port:8e3,open:process.platform==="darwin",hot:!0,watchFiles:["src/**/*.html"],static:[{directory:this.store.publicDir,watch:this.store.isDev}],allowedHosts:["all"],historyApiFallback:!0,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, PATCH, OPTIONS","Access-Control-Allow-Headers":"X-Requested-With, content-type, Authorization"}};return this.assign(t,this.store.empOptions.server)}get empShare(){return this.assign({name:"",filename:"emp.js",shared:{},mfVersion:1.5},this.store.empOptions.empShare)}get css(){return this.assign({postcss:[]},this.store.empOptions.css)}get output(){let t=(this.store.isDev,".[contenthash:8]"),e=this.store.isDev?"":".[contenthash:8]",{assetsDir:s,staticDir:i}=this.store.empConfig.build,o={publicPath:this.store.empConfig.base?this.store.empConfig.base:"auto",crossOriginLoading:"anonymous",filename:`${i}js/[name]${t}.js`,cssFilename:`${i}css/[name]${e}.css`,cssChunkFilename:`${i}css/[name]${e}.css`,assetModuleFilename:`${i}${s}/[name]${t}[ext][query]`,path:this.store.outDir,clean:!0};return this.assign(o,this.store.empOptions.output)}get define(){let t={mode:this.store.mode,env:this.store.cliOptions.env};return this.store.empOptions.define&&(t={...t,...this.store.empOptions.define}),this.setDefine(t)}setDefine(t){let e=this.store.empOptions.defineFix?this.store.empOptions.defineFix:this.isESM?"esm":"cjs",s={};return Object.keys(t).map(i=>{(e==="all"||e==="esm")&&(s[`import.meta.env.${i}`]=JSON.stringify(t[i])),(e==="all"||e==="cjs")&&(s[`process.env.${i}`]=JSON.stringify(t[i])),s[`${i}`]=JSON.stringify(t[i])}),s}get externals(){return this.assign(this.empShareLib.externals,this.store.empOptions.externals)}get resolve(){return g({alias:{src:this.store.resolve("src"),"@":this.store.resolve("src")},extensions:["...",".js",".jsx",".mjs",".ts",".tsx",".css",".less",".scss",".sass",".json",".wasm",".vue",".svg",".svga"]},this.store.empOptions.resolve)}async syncEmpOptions(){let t=this.store.resolve("emp-config.js");if(!be.existsSync(t))return;let{default:e}=await import(this.store.importFileUrl(t));typeof e=="function"?this.store.empOptions=await e(this.store):this.store.empOptions=e||{}}get moduleTransformRule(){let{moduleTransform:t}=this.store.empOptions,e=this.assign({defaultExclude:!1},t),s={and:[],not:[]};return e.defaultExclude===!0&&s.and.push(/(node_modules|bower_components)/),e?.exclude&&(s.and=s.and.concat(e.exclude)),t?.include&&(s.not=e.include),s}get cacheDir(){return this.store.empOptions.cacheDir?this.store.empOptions.cacheDir:"node_modules/.emp-cache"}get lifeCycle(){return this.assign({},this.store.empOptions.lifeCycle)}get reactRuntime(){if(this.store.reactVersion)return this.store.empOptions.reactRuntime?this.store.empOptions.reactRuntime:R(this.store.reactVersion,"17")>-1?"automatic":"classic"}},Bt=new tt});import v from"node:path";import ve from"node:fs/promises";import Ce from"webpack-chain";import{pathToFileURL as we}from"node:url";import xe from"node:util";var et,n,d=l(()=>{"use strict";dt();Tt();b();Gt();y();et=class{empPkg={dependencies:{},devDependencies:{},version:"2.0.0",name:""};pkg={dependencies:{},devDependencies:{},version:"0.0.0",name:""};root=process.cwd();empRoot=gt;empSource=v.resolve(this.empRoot,"dist");resolve=t=>v.isAbsolute(t)?t:v.resolve(this.root,t);empResolve=t=>v.resolve(this.empRoot,t);appSrc="";outDir="";publicDir="";resource={dir:"",key:"",cert:""};cacheDir="";mode="development";cliMode="dev";isDev=!0;reactVersion=void 0;cliOptions;chain;rsConfig;empOptions={};empConfig;async setup(t,e){await this.initVars(t,e),this.empConfig=Bt,await this.empConfig.setup(this),this.initPaths(),this.chain=new Ce,await jt.setup(this),this.setLogger(),this.toConfig(),this.logConfig()}async initVars(t,e){this.cliOptions=e||{},this.cliMode="prod",this.mode=t==="dev"?"development":"production",this.isDev=this.mode==="development";let s=await U(this.empResolve("package.json")),i=await U(this.resolve("package.json"));this.empPkg={...this.empPkg,...s},this.pkg={...this.pkg,...i},this.reactVersion=this.pkg.dependencies.react||this.pkg.devDependencies.react}initPaths(){this.appSrc=this.resolve(this.empConfig.appSrc),this.outDir=this.resolve(this.empConfig.build.outDir),this.publicDir=this.resolve(this.empConfig.build.publicDir),this.cacheDir=this.resolve(this.empConfig.cacheDir),this.resource.dir=v.join(this.empRoot,"resource"),this.resource.cert=v.join(this.resource.dir,"emp.cert"),this.resource.key=v.join(this.resource.dir,"emp.key")}setLogger(){let t=this.cliMode==="dev"?"debug":"info";this.empConfig.debug.loggerLevel&&(t=this.empConfig.debug.loggerLevel),a.setup({pname:`EMP\u26A1${this.empPkg.version}${this.cliMode==="dev"?".DEV":""}`,logLevel:t})}merge(t){this.chain.merge(t)}importResolve(t,e){return ut(t,e)}importFileUrl(t){return we(t).toString()}toConfig(){this.rsConfig=this.chain.toConfig()}logConfig(){if(this.empConfig.debug.showRsconfig)if(typeof this.empConfig.debug.showRsconfig=="string"){let t=v.join(this.root,this.empConfig.debug.showRsconfig);ve.writeFile(t,JSON.stringify(this.rsConfig,null,2))}else{let t={colors:!0,depth:null},e=typeof this.empConfig.debug.showRsconfig=="object"?g(t,this.empConfig.debug.showRsconfig):t;console.log(a.link("[Compile Config]")),console.log(xe.inspect(this.rsConfig,e))}}},n=new et});import{exec as Se}from"node:child_process";import{promisify as Ee}from"node:util";var It,Ut,Oe,$e,Ht,Nt=l(()=>{"use strict";b();d();It=Ee(Se),Ut=["Google Chrome Canary","Google Chrome Dev","Google Chrome Beta","Google Chrome","Microsoft Edge","Brave Browser","Vivaldi","Chromium"],Oe=async()=>{let r=process.env.BROWSER;if(!r||!Ut.includes(r)){let{stdout:t}=await It("ps cax");r=Ut.find(e=>t.includes(e))}return r},$e=async r=>{if(process.platform==="darwin")try{let e=await Oe();if(e){let s=`osascript openChrome.applescript "${encodeURI(r)}" "${e}"`;return await It(s,{cwd:n.resource.dir}),!0}}catch(e){a.debug(e)}try{let{default:e}=await import("open");return await e(r),!0}catch(e){return a.error("Failed to open start URL."),a.error(e),!1}},Ht=$e});import Pe from"net";import ke from"os";async function Vt(r,t="localhost"){if(r!==Re&&(r<_t||r>st))throw new Error(`Port number must lie between ${_t} and ${st}`);let e=r,s=Le(),i;t&&!s.has(t)?i=new Set([t]):i=s;let o=new Set(["EADDRINUSE","EACCES"]);for(;e<=st;)try{return await Te(e,i)}catch(p){if(!o.has(p.code))throw p;e+=1}throw new Error("No available ports found")}var _t,st,Re,Le,je,Te,Jt=l(()=>{"use strict";_t=1024,st=65535,Re=443,Le=()=>{let r=ke.networkInterfaces(),t=new Set([void 0,"0.0.0.0"]);for(let e of Object.values(r))if(e)for(let s of e)t.add(s.address);return t},je=(r,t)=>new Promise((e,s)=>{let i=Pe.createServer();i.unref(),i.on("error",s),i.listen(r,t,()=>{let{port:o}=i.address();i.close(()=>{e(o)})})}),Te=async(r,t)=>{let e=new Set(["EADDRNOTAVAIL","EINVAL"]);for(let s of t)try{await je(r,s)}catch(i){if(!e.has(i.code))throw i}return r}});import Wt from"node:fs/promises";import T from"chalk";var C,D=l(()=>{"use strict";b();d();y();Q();Nt();Jt();Z();C=class{sf={protocol:"http",host:"0.0.0.0",port:8e3,publicPath:"",publicHasHttp:!1,isOpenBrower:!1,url:"",urls:{localUrlForBrowser:"",localUrlForTerminal:"",lanUrlForTerminal:"",lanUrlForConfig:""}};async adaptServer(){this.sf.publicPath=n.rsConfig.output?.publicPath==="auto"?"/":n.rsConfig.output?.publicPath||"/",this.sf.isOpenBrower=!!n.empConfig.server.open,this.sf.protocol=this.isHttps?"https":"http",this.sf.host=n.empConfig.server.host?n.empConfig.server.host:this.sf.host,this.sf.port=n.empConfig.server.port,await this.serverPort(),O.setup(this.sf),this.sf.publicPath&&(this.sf.publicPath.indexOf("http://")>-1||this.sf.publicPath.indexOf("https://")>-1)?(this.sf.url=this.sf.publicPath,this.sf.publicHasHttp=!0,this.sf.urls.localUrlForTerminal=O.prettyPrintUrl("localhost")):(this.sf.urls=O.urls,this.sf.url=this.sf.urls.localUrlForBrowser)}startOpen(){let{urls:t}=this.sf;this.sf.publicHasHttp?(a.info(`${T.greenBright("\u279C")} Local: ${a.link(t.localUrlForTerminal)}`),a.info(`${T.greenBright("\u279C")} Network: ${a.link(this.sf.publicPath)}`)):(a.info(`${T.greenBright("\u279C")} Local: ${a.link(t.localUrlForTerminal)}`),a.info(`${T.greenBright("\u279C")} Network: ${a.link(t.lanUrlForTerminal)}
10
- `)),this.sf.isOpenBrower&&Ht(this.sf.url)}async setup(t,e){await n.setup(t,e),n.empConfig.debug.clearLog&&Et(),a.title(`${t}`),await this.adaptServer(),await this.run()}async run(){}get isHttps(){let{server:t,https:e}=n.empConfig.server||{};return t==="https"||typeof t=="object"&&t.type==="https"||e===!0}getcert(){return Promise.all([Wt.readFile(n.resource.key),Wt.readFile(n.resource.cert)])}async serverPort(){if(j.isADB)return;let{port:t,host:e}=this.sf,s=await Vt(t,e);s!==t&&(this.sf.port=s,n.rsConfig.devServer?.port&&(n.rsConfig.devServer.port=s))}}});import u from"chalk";import w from"node:path";import{gzipSizeSync as De}from"gzip-size";import Fe from"node:fs";function Ie(r,t){let e=[r,t],s=["File","Size","Gzipped"].reduce((i,o,p)=>{let c=e[p],h=o;return c&&(h=o.length<c?o+" ".repeat(c-o.length):o),`${i+h} `}," ");console.log(u.bold.blue(s))}async function Xt(r){let t=r.toJson({all:!1,assets:!0,timings:!0});k(t.time);let s=t.assets.filter(m=>Be(m.name)).map(Ue);s.sort((m,P)=>m.size-P.size);let i=Math.max(...s.map(m=>m.sizeLabel.length)),o=Math.max(...s.map(m=>(m.folder+w.sep+m.name).length));Ie(o,i);let p=0,c=0;s.forEach(m=>{let{sizeLabel:P}=m,{name:ie,folder:oe,gzipSizeLabel:ne}=m,lt=(oe+w.sep+ie).length,ct=P.length;if(p+=m.size,c+=m.gzippedSize,ct<i){let z=" ".repeat(i-ct);P+=z}let mt=u.gray(m.folder+w.sep)+He(m.name);if(lt<o){let z=" ".repeat(o-lt);mt+=z}a.info(` ${mt} ${u.gray(P)} ${ne}`)});let h=`${u.bold.blue("Total size:")} ${F(p)}`,$=`${u.bold.blue("Gzipped size:")} ${F(c)}`;a.info(`
11
- ${h}
12
- ${$}
13
- `)}function k(r=0){a.info(`${u.greenBright("\u2713")} Ready in ${Ot(Number(r))}`)}var Me,Ae,ze,Be,Ge,Ue,F,He,M=l(()=>{"use strict";d();b();y();Me=/\.html$/,Ae=/\.(?:js|mjs|cjs|jsx)$/,ze=/\.css$/,Be=r=>!/\.map$/.test(r)&&!/\.LICENSE\.txt$/.test(r),Ge=r=>r>300*1e3?u.red:r>100*1e3?u.yellow:u.white,Ue=r=>{let t=r.name.split("?")[0],e=F(r.size),s=w.basename(t),i=w.join(w.basename(n.empConfig.build.outDir),w.dirname(t)),o=Fe.readFileSync(w.join(n.empConfig.build.outDir,t)),p=o.length,c=De(o),h=Ge(c)(F(c));return{size:p,folder:i,name:s,gzippedSize:c,sizeLabel:e,gzipSizeLabel:h}};F=r=>{let t=r/1e3;return`${t.toFixed(t<1?2:1)} kB`},He=r=>Ae.test(r)?u.yellowBright(r):ze.test(r)?u.greenBright(r):Me.test(r)?u.blueBright(r):u.magenta(r)});var qt={};B(qt,{default:()=>Ve});import{rspack as Ne}from"@rspack/core";import{RspackDevServer as _e}from"@rspack/dev-server";var rt,Ve,Qt=l(()=>{"use strict";d();D();b();y();M();rt=class extends C{async run(){let t=g(n.rsConfig,{stats:{all:!1,colors:!0,assets:!1,chunks:!1,entrypoints:!1,timings:!1,version:!1,errors:!0,warnings:!0},devServer:{open:!1,setupExitSignals:!0}}),e=Ne(t);if(!n.rsConfig.devServer){a.error("devServer is not defined in config");return}let s=Object.assign({},n.rsConfig.devServer);if(this.isHttps&&(s.https===!0&&delete s.https,!s.server)){let[c,h]=await this.getcert();s.server={type:"https",options:{key:c,cert:h}}}let{afterDevServe:i,beforeDevServe:o}=n.empConfig.lifeCycle,p=new _e(s,e);this.startOpen(),o&&o(),await p.start(),p.middleware?.waitUntilValid(c=>{let h=c?.toJson({all:!1,colors:!1,assets:!1,chunks:!1,timings:!0});k(h.time),i&&i()})}},Ve=new rt});var Yt={};B(Yt,{default:()=>We});import{rspack as Je}from"@rspack/core";var it,We,Zt=l(()=>{"use strict";b();d();D();M();it=class extends C{async run(){let{afterBulid:t,beforeBuild:e}=n.empConfig.lifeCycle;e&&e(),Je(n.rsConfig,async(s,i)=>{if(s!==null){a.error(s.stack||s),s.message&&a.error(s.message);return}if(!i){a.red("Stats is Undefined.");return}i.hasErrors()&&(a.error(i.toString({colors:!0,children:!0})),a.red("Failed to compile."),process.exit(1)),i.hasWarnings()&&(a.yellow("Compiled with warnings."),a.warn(i.toString({colors:!0,children:!0}))),await Xt(i),t&&t()})}},We=new it});import Xe from"express";import qe from"cors";import Qe from"compression";import Ye from"https";var A,Kt=l(()=>{"use strict";D();A=class extends C{app;async init(){let t=Xe();t.use(Qe()),t.use(qe()),this.app=t}async server(){if(this.isHttps){let[t,e]=await this.getcert();Ye.createServer(typeof this.isHttps!="boolean"?this.isHttps:{key:t,cert:e},this.app).listen(this.sf.port,async()=>{this.startOpen(),await this.onReady()})}else this.app.listen(this.sf.port,async()=>{this.startOpen(),await this.onReady()})}async onReady(){}async middleware(){}async start(){await this.init(),await this.middleware(),await this.server()}}});var te={};B(te,{default:()=>ss});import Ze from"express";import Ke from"path";import ts from"node:fs/promises";import es from"node:fs";var ot,ss,ee=l(()=>{"use strict";Kt();d();b();M();ot=class extends A{timing=0;async run(){if(this.timing=Date.now(),!es.existsSync(n.outDir))return a.sysError(`emp serve must be executed after emp build,${n.outDir} not exist!`);let{beforeServe:t}=n.empConfig.lifeCycle;t&&t(),this.start()}async middleware(){let t=n.resolve(n.rsConfig.output?.path);this.app.use(Ze.static(t));let e=await ts.readFile(Ke.join(t,"index.html"),"utf8");this.app.get("*",(s,i)=>i.send(e))}async onReady(){k(Date.now()-this.timing);let{afterServe:t}=n.empConfig.lifeCycle;t&&t()}},ss=new ot});d();d();y();b();import{program as S}from"commander";import nt,{exit as rs}from"node:process";function se(){let r="20.0.0";R(r,nt.versions.node)===1&&(a.sysError(`\u5F53\u524D\u7248\u672C\u4E3Av${nt.versions.node} \u6700\u4F4E\u8981\u6C42\u4E3Av${r}`),rs(0)),S.version(n.empPkg.version,"-v, --version").usage("<command> [options]"),S.command("dev").description("Dev \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-h, --hot","\u662F\u5426\u4F7F\u7528\u70ED\u66F4\u65B0 \u9ED8\u8BA4\u542F\u52A8").option("-o, --open","\u662F\u5426\u6253\u5F00\u8C03\u8BD5\u9875\u9762 \u9ED8\u8BA4\u4E0D\u6253\u5F00").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").option("-ev, --env-vars <key=value>","\u5B9A\u4E49\u4E00\u4E2A\u73AF\u5883\u53D8\u91CF -ev key=value \u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u91CD\u590D\u8C03\u7528 -ev key=value -ev key=value",(t,e)=>{let[s,i]=t.split("=");return e[s]=i,e},{}).action(async t=>{let{default:e}=await Promise.resolve().then(()=>(Qt(),qt));await e.setup("dev",t)}),S.command("build").description("Build \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-a, --analyze","\u751F\u6210\u5206\u6790\u62A5\u544A \u9ED8\u8BA4\u4E3A false").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").option("-ev, --env-vars <key=value>","\u5B9A\u4E49\u4E00\u4E2A\u73AF\u5883\u53D8\u91CF -ev key=value \u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u91CD\u590D\u8C03\u7528 -ev key=value -ev key=value",(t,e)=>{let[s,i]=t.split("=");return e[s]=i,e},{}).action(async t=>{let{default:e}=await Promise.resolve().then(()=>(Zt(),Yt));await e.setup("build",t)}),S.command("serve").description("Server \u6A21\u5F0F").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async t=>{let{default:e}=await Promise.resolve().then(()=>(ee(),te));await e.setup("serve",t)}),S.command("dts").description("\u62C9\u53D6 remote \u9879\u76EE\u7684 d.ts").option("-p, --typingsPath <typingsPath>","\u4E0B\u8F7D\u76EE\u5F55").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").action(t=>{}),S.command("init").description("\u521D\u59CB\u5316 emp \u9879\u76EE").option("-d, --data [data]","JSON\u6570\u636E http\u5730\u5740 \u6216\u8005 \u6587\u4EF6\u8DEF\u5F84\u76F8\u5BF9\u3001\u7EDD\u5BF9\u8DEF\u5F84").action(t=>{}),S.parse(nt.argv)}d();import is from"fast-glob";import re from"node:fs/promises";import pt from"node:path";var os=/(?:(?:import|export)\s?(?:type)?\s?(?:(?:\{[^;\n]+\})|(?:[^;\n]+))\s?from\s?['"][^;\n]+['"])|(?:import\(['"][^;\n]+?['"]\))/g,ns=/(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)['"]/,ps=/import\(['"]([^;\n]+?)['"]\)/,at=class{list=[];outDir=n.resolve("dist");aliasName="@empjs/cli";async setup(t,e){t&&(this.outDir=t),e&&(this.aliasName=e);let s=await this.readDts();await this.writeCode(s)}async readDts(){this.list=await is([`${n.empConfig.build.outDir}/**/*.d.ts`]);let t=[];this.list.map(s=>{s=n.resolve(s),t.push(this.readFile(s))});let e=await Promise.all(t);return e=e.map(s=>this.replaceAliasPath(s)),e}async readFile(t){let e=await re.readFile(t,{encoding:"utf-8"});return{src:t,code:e}}replaceAliasPath({src:t,code:e}){e=e.replace(os,i=>{let o=i.match(ns);if(o||(o=i.match(ps)),o&&o[1]){let p=o[1];if(!p.startsWith("."))return i;let c=pt.resolve(pt.dirname(t),p).replace(this.outDir,this.aliasName);return i.replace(o[1],c)}return i});let s=t.replace(this.outDir,this.aliasName).replace(".d.ts","");return s.endsWith("/index")&&(s=s.replace("/index","")),e=this.warpDeclareModule(s,e),{code:e,src:t,mod:s}}warpDeclareModule(t,e){return`declare module '${t}' {\r
14
- ${e}}\r
15
- `}async writeCode(t){let e="";t.map(s=>{e+=s.code}),await re.writeFile(pt.join(this.outDir.replace("dist","types"),"type.d.ts"),e)}},as=new at;function Ri(r){return r}export{Ri as defineConfig,as as dts,se as runScript,n as store};
1
+ var gt=Object.defineProperty;var l=(i,e)=>()=>(i&&(e=i(i=0)),e);var N=(i,e)=>{for(var t in e)gt(i,t,{get:e[t],enumerable:!0})};import{fileURLToPath as dt}from"node:url";import{dirname as yt}from"node:path";import{readFile as bt}from"node:fs/promises";import ye from"node:module";import J from"node:path";var be,vt,V,j,ve,Ce,_=l(()=>{"use strict";be=dt(import.meta.url),vt=yt(be),V=async i=>{try{let e=await bt(i);return JSON.parse(e)}catch(e){console.error(e)}},j=ye.createRequire(import.meta.url),ve=(i,e)=>{let t=j;return e&&(t=ye.createRequire(e)),t.resolve(i)},Ce=J.resolve(vt,be).replace(`${J.sep}dist${J.sep}index.js`,"")});import E from"@rspack/core";import we from"fs";var W,Se,xe=l(()=>{"use strict";W=class{store;async setup(e){this.store=e;let t=[this.define(),this.anylayze(),this.progress(),this.copy(),this.empShare(),this.minify()];await this.store.empConfig.lifeCycle.beforePlugin(),await Promise.all(t),await this.store.empConfig.lifeCycle.afterPlugin()}async anylayze(){if(!this.store.cliOptions.analyze)return;let{default:{BundleAnalyzerPlugin:e}}=await import("webpack-bundle-analyzer");this.store.chain.plugin("bundleAnalyzerPlugin").use(e,[{}])}async define(){this.store.chain.plugin("definePlugin").use(E.DefinePlugin,[this.store.empConfig.define])}async copy(){let e=this.store.resolve("public");we.existsSync(e)&&we.readdirSync(e).length>0&&this.store.chain.plugin("copyRspackPlugin").use(E.CopyRspackPlugin,[{patterns:[{from:e,to:this.store.resolve("dist")}]}])}async progress(){this.store.empConfig.debug.progress&&this.store.chain.plugin("progressPlugin").use(E.ProgressPlugin,[{prefix:"EMP"}])}async empShare(){let{version:e,isEmpshare:t}=this.store.empConfig.empShareLib;if(!t)return;let{ModuleFederationPluginV1:s,ModuleFederationPlugin:r}=E.container,o=e===1?s:r;this.store.chain.plugin("empShare").use(o,[this.store.empConfig.empShareLib.pluginConfig])}minify(){this.store.chain.optimization.minimize(this.store.mode==="production"),this.store.chain.optimization.minimizer("minJs").use(E.SwcJsMinimizerRspackPlugin,[this.store.empConfig.build.minOptions]),this.store.chain.optimization.minimizer("minCss").use(E.SwcCssMinimizerRspackPlugin,[{}])}},Se=new W});import Ct from"chalk";import wt from"fs-extra";function Oe(){process.stdout.write(process.platform==="win32"?"\x1B[2J\x1B[0f":"\x1B[2J\x1B[3J\x1B[H")}function f(i,...e){for(let t of e)for(let s in t){let r=t[s],o=i[s];if(Object(r)==r&&Object(o)===o){i[s]=f(o,r);continue}i[s]=t[s]}return i}var Ee,T,Pe,$e,y=l(()=>{"use strict";Ee=i=>{console.log(i);try{let{version:e}=wt.readJSONSync(i);return console.log(e),e}catch{return}};T=(i="",e="")=>{let t=i.replace("^","").split("."),s=e.replace("^","").split("."),r=Math.max(t.length,s.length),o=0;for(let p=0;p<r;p++){let c=t.length>p?t[p]:0,u=isNaN(Number(c))?c.charCodeAt():Number(c),P=s.length>p?s[p]:0,m=isNaN(Number(P))?P.charCodeAt():Number(P);if(u<m){o=-1;break}else if(u>m){o=1;break}}return o},Pe=i=>{i=i/1e3;let e=s=>Ct.bold(s);if(i<1)return`${i*1e3} ms`;if(i<10){let s=i>=.01?2:3;return`${e(i.toFixed(s))} s`}if(i<60)return`${e(i.toFixed(1))} s`;let t=i/60;return`${e(t.toFixed(2))} m`},$e=i=>`data:text/javascript,${i}`});import ke from"node:path";var X,je,Te=l(()=>{"use strict";_();y();X=class{store;swcJsOptions={};swcTsOptions={};coreJs={version:"3",alias:"",path:""};async setup(e){this.store=e;let t=[this.react(),this.files(),this.scripts()];await Promise.all(t)}swcParser(e){switch(e){case"js":return{syntax:"typescript",decorators:!0,tsx:!0,dynamicImport:!0};case"ts":return{syntax:"typescript",decorators:!0,tsx:!0,dynamicImport:!0}}}get swcTransform(){let{isDev:e}=this.store;return this.store.reactVersion?{react:{runtime:this.store.empConfig.reactRuntime,development:e,refresh:e}}:{}}swcJsc(e){let{target:t,externalHelpers:s}=this.store.empConfig.build;return{parser:this.swcParser(e),transform:this.swcTransform,target:t,externalHelpers:s,preserveAllComments:!0}}get swcCoreVersion(){let[e,t]=this.coreJs.version.split(".");return`${e}.${t}`}swcOptions(e){let t={jsc:this.swcJsc(e),isModule:"unknown"};return this.store.empConfig.build.polyfill&&(delete t.jsc.target,t.env={mode:this.store.empConfig.build.polyfill,coreJs:this.swcCoreVersion,targets:this.store.empConfig.build.browserslist}),this.store.empConfig.build.polyfill&&(t.env.include=["es.object.values","es.array.flat"]),t}swcInitOptions(){let{externalHelpers:e}=this.store.empConfig.build;e&&this.store.chain.resolve.alias.set("@swc/helpers",ke.dirname(j.resolve("@swc/helpers/package.json"))),this.coreJs.path=j.resolve("core-js/package.json");let t=Ee(this.coreJs.path);t&&(this.coreJs.version=t),this.coreJs.alias=ke.dirname(this.coreJs.path),this.store.empConfig.build.polyfill&&(this.store.chain.resolve.alias.set("core-js",this.coreJs.alias),this.store.chain.module.rule("javascript").exclude.add(/core-js/),this.store.chain.module.rule("typescript").exclude.add(/core-js/)),this.swcTsOptions=this.swcOptions("ts"),this.swcJsOptions=this.swcOptions("js")}async scripts(){this.swcInitOptions();let e=!1,t=[];this.store.chain.merge({module:{parser:{javascript:{exportsPresence:"error",importExportsPresence:"error"}},rule:{mjs:{test:/\.m?js/,resolve:{fullySpecified:!1}},typescript:{test:/\.(ts|tsx)$/,exclude:t,sideEffects:e,use:[{loader:"builtin:swc-loader",options:this.swcTsOptions}]},javascript:{test:/\.(js|jsx)$/,exclude:t,sideEffects:e,use:[{loader:"builtin:swc-loader",options:this.swcJsOptions}]}}}})}async react(){if(this.store.reactVersion&&(this.store.empConfig.react.svgr&&this.store.chain.merge({module:{rule:{svg:{test:/\.svg$/,issuer:/\.[jt]sx?$/,resourceQuery:/svgr/,use:[{loader:this.store.importResolve("@svgr/webpack"),options:{}}]}}}}),this.store.isDev&&this.store.empConfig.react.hmr)){let{default:e}=await import("@rspack/plugin-react-refresh"),t={};this.store.empConfig.empShareLib.config.name&&(t.library=this.store.empConfig.empShareLib.config.name),this.store.chain.plugin("plugin-react-refresh").use(e,[t])}}async files(){(!this.store.reactVersion||!this.store.empConfig.react.svgr)&&this.store.chain.merge({module:{rule:{svg:{test:/\.svg$/,type:"asset/resource"}}}}),this.store.chain.merge({module:{rule:{inline:{resourceQuery:/inline/,type:"asset/inline"}}}}),this.store.chain.merge({module:{rule:{image:{test:/\.(png|jpe?g|gif|webp|ico)$/i,type:"asset/resource"},fonts:{test:/\.(|otf|ttf|eot|woff|woff2)$/i,type:"asset/resource"},svga:{test:/\.(svga)$/i,type:"asset/resource"}}}})}},je=new X});var q,Re,De=l(()=>{"use strict";q=class{store;async setup(e){this.store=e;let t=[this.common(),this.stats(),this.devServer(),this.optimization()];await Promise.all(t)}async common(){this.store.merge({node:{global:!0},experiments:{rspackFuture:{newTreeshaking:this.store.empConfig.isESM},outputModule:this.store.empConfig.isESM,topLevelAwait:!0},target:this.store.empConfig.target,infrastructureLogging:this.store.empConfig.debug.infrastructureLogging,context:this.store.root,mode:this.store.mode,cache:this.store.empConfig.debug.rspackCache,devtool:this.store.empConfig.build.sourcemap?"source-map":!1,builtins:{css:{modules:{localIdentName:this.store.isDev?"[path][name]-[local]-[hash:5]":"[local]-[hash:5]"}}},output:this.store.empConfig.output,resolve:this.store.empConfig.resolve,externals:this.store.empConfig.externals})}async stats(){this.store.merge({stats:{colors:!0,all:!1,assets:!1,chunks:!1,timings:!0,version:!0}})}async devServer(){this.store.merge({devServer:this.store.empConfig.server})}async optimization(){let e={moduleIds:this.store.empConfig.build.moduleIds,chunkIds:this.store.empConfig.build.chunkIds,minimize:this.store.empConfig.build.minify,splitChunks:{chunks:"async",cacheGroups:{}}};this.store.empConfig.build.polyfill&&(e.splitChunks.cacheGroups={}),this.store.chain.merge({optimization:e})}},Re=new q});import Ae from"html-webpack-plugin";var Le,R,Me,D,St,L,Q=l(()=>{"use strict";y();Le="HtmlImportMapPlugin",R=class{importMap;constructor(e){this.importMap=e}apply(e){e.hooks.compilation.tap(Le,t=>{Ae.getHooks(t).alterAssetTagGroups.tapAsync(Le,(s,r)=>{s.headTags.push({tagName:"script",attributes:{type:"importmap"},innerHTML:`${JSON.stringify(this.importMap,null,2)}`,voidTag:!1,meta:{plugin:void 0}}),r(null,s)})})}},Me="HtmlEmpShareLibPlugin",D=class{files;constructor(e){this.files=f({js:[],css:[]},e)}apply(e){e.hooks.compilation.tap(Me,t=>{let s=this.files;Ae.getHooks(t).alterAssetTagGroups.tapAsync(Me,(r,o)=>{s.js.map(p=>{r.headTags.push({tagName:"script",attributes:{src:p},voidTag:!1,meta:{plugin:void 0}})}),s.css.map(p=>{r.headTags.push({tagName:"link",attributes:{rel:"stylesheet",href:p},voidTag:!1,meta:{plugin:void 0}})}),o(null,r)})})}},St=()=>{let i=["import 'core-js'"].join(`
2
+ `);return $e(i)},L=class{constructor(){}apply(e){let{webpack:t}=e;new t.EntryPlugin(e.context,St(),{name:void 0}).apply(e)}}});import xt from"html-webpack-plugin";import Et from"fast-glob";import S from"node:path";var Y,Fe,Be=l(()=>{"use strict";y();Q();Y=class{store;entriesConfig={};async setup(e){this.store=e,await this.init(),this.toConfig()}setHtmlConfig(e,t){return e.template=this.setTemplate(e.template),e.favicon=this.setFavicion(e.favicon),e.chunks=t,e.filename=`${t[0]}.html`,this.store.empConfig.base&&(e.publicPath=this.store.empConfig.base),e.tags=e.tags||{},e}setChunk(e){return e.replace(S.extname(e),"").replace(`${this.store.empConfig.appSrc}${S.sep}`,"")}setTemplate(e){return e?this.store.resolve(e):this.store.empResolve(S.join("template","index.html"))}setFavicion(e){return e?this.store.resolve(e):this.store.empResolve(S.join("template","favicon.ico"))}setEntryItem(e,t,s){s=s||this.store.resolve(S.join(this.store.empConfig.appSrc,e));let r=this.setChunk(e),o=[s];this.entriesConfig[r]={entry:{[r]:o},html:this.setHtmlConfig(t,[r])}}setRspackHtmlPlugin(e,t){this.store.chain.plugin(`html-plugin-${t}`).use(xt,[e]),this.store.empConfig.empShareLib&&(e.files=f(e.files,this.store.empConfig.empShareLib.externalAssets)),this.store.chain.plugin(`html-plugin-empShare-${t}`).use(D,[e.files]),this.store.empConfig.empShareLib.useImportMap&&this.store.chain.plugin(`html-plugin-import-map-${t}`).use(R,[this.store.empConfig.empShareLib.importMap])}setRspackEntry(e){this.store.merge({entry:e})}async init(){let e=S.join(this.store.appSrc,this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index.{ts,tsx,jsx,js}").replace(/\\/g,"/"),t=await Et([e]);if(t[0]){let s=S.join(this.store.empConfig.appSrc,Object.keys(this.store.empConfig.entries).length>0&&this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index");this.setEntryItem(s,this.store.empConfig.html,t[0])}if(Object.keys(this.store.empConfig.entries).length>0)for(let[s,r]of Object.entries(this.store.empConfig.entries))this.setEntryItem(s,{...this.store.empConfig.html,...r})}toConfig(){for(let[e,t]of Object.entries(this.entriesConfig))this.setRspackHtmlPlugin(t.html,e),this.setRspackEntry(t.entry)}},Fe=new Y});var Z,ze,Ge=l(()=>{"use strict";Z=class{store;async setup(e){this.store=e;let t=[this.sass(),this.less(),this.css()];await Promise.all(t)}async sass(){let e={loader:this.store.importResolve("sass-loader"),options:{}};this.store.chain.merge({module:{rule:{sass:{test:/\.(sass|scss)$/,use:{postcss:this.postcss,sassLoader:e},type:"css/auto"}}}})}async less(){let e={loader:this.store.importResolve("less-loader"),options:{lessOptions:{javascriptEnabled:!0}}};this.store.chain.merge({module:{rule:{less:{test:/\.less$/,use:{postcss:this.postcss,lessLoader:e},type:"css/auto"}}}})}async css(){this.store.chain.merge({module:{rule:{css:{test:/\.css$/,use:{postcss:this.postcss},type:"css/auto"}}}})}get postcss(){return{loader:this.store.importResolve("postcss-loader"),options:{postcssOptions:{plugins:this.store.empConfig.css.postcss}}}}},ze=new Z});var K,Ie,He=l(()=>{"use strict";xe();Te();De();Be();Ge();K=class{store;async setup(e){this.store=e;let t=[Re.setup(this.store),je.setup(this.store),Se.setup(this.store),Fe.setup(this.store),ze.setup(this.store)];await Promise.all(t),await this.store.empConfig.plugins(),await this.store.empConfig.chain()}},Ie=new K});import h from"chalk";import{table as Ot}from"table";var ee,a,b=l(()=>{"use strict";ee=class{pname="";logLevel="debug";setup({pname:e,logLevel:t}){this.pname=e,t&&(this.logLevel=t)}debug=(...e)=>["debug"].includes(this.logLevel)&&console.log(...e);info=(...e)=>["debug","info"].includes(this.logLevel)&&console.log(...e);warn=(...e)=>["debug","info","warn"].includes(this.logLevel)&&console.warn(...e);error=(...e)=>["debug","info","warn","error"].includes(this.logLevel)&&console.error(...e);blue=e=>{console.log(`${h.white.bgBlue(this.pname)}${h.blue.bgWhite(` ${e} `)}
3
+ `)};cyan=e=>{console.log(`${h.white.bgCyan(this.pname)}${h.cyan.bgWhite(` ${e} `)}
4
+ `)};magenta=e=>{console.log(`${h.white.bgMagenta(this.pname)}${h.magenta.bgWhite(` ${e} `)}
5
+ `)};green=e=>{console.log(`${h.white.bgGreen(this.pname)}${h.green.bgWhite(` ${e} `)}
6
+ `)};yellow=e=>{console.log(`${h.white.bgYellow(this.pname)}${h.yellow.bgWhite(` ${e} `)}
7
+ `)};red=e=>{console.log(`${h.white.bgRed(this.pname)}${h.red.bgWhite(` ${e} `)}
8
+ `)};sysError=e=>{console.log(`${h.white.bgRed(" System Error Tips ")}${h.red.bgWhite(` ${e} `)}
9
+ `)};link=e=>h.hex("#3498db")(e);title=e=>{console.log(`${h.greenBright.bold(`${this.pname}`)} ${h.bgGreenBright(` ${e} `)}
10
+ `)};tableData=[];tableConfig={border:{topBody:"\u2500",topJoin:"\u252C",topLeft:"\u250C",topRight:"\u2510",bottomBody:"\u2500",bottomJoin:"\u2534",bottomLeft:"\u2514",bottomRight:"\u2518",bodyLeft:"\u2502",bodyRight:"\u2502",bodyJoin:"\u2502",joinBody:"\u2500",joinLeft:"\u251C",joinRight:"\u2524",joinJoin:"\u253C"}};tableInput(e){this.tableData.push(e)}tableOutput(){console.log(Ot(this.tableData,this.tableConfig))}},a=new ee});var M,Ue=l(()=>{"use strict";g();M=class{externals={};externalAssets={js:[],css:[]};exp=/^([0-9a-zA-Z_\s]+)@(.*)/;config;importMap={imports:{}};version;isEmpshare=!1;async setup(){this.config=n.empConfig.empShare,this.version=n.empConfig.empShare.mfVersion,this.isEmpshare=!!n.empConfig.empShare.name,this.config.shareLib&&this.setShareLib(),this.prepareEsm()}get useImportMap(){return this.config.useImportMap&&n.empConfig.isESM}get pluginConfig(){let e={...this.config,implementation:n.importResolve("@module-federation/runtime")};return delete e.mfVersion,delete e.shareLib,delete e.useImportMap,e}prepareEsm(){if(n.empConfig.isESM){this.config.library={type:"module"};let e=this.config.remotes||{};for(let[t,s]of Object.entries(e))if(typeof s=="string"){let r=s.match(this.exp)||[];r.length>0&&(e[t]=r[2])}this.config.remotes=e}}async setShareLib(){let e=this.config,t=[];if(typeof e.shareLib=="object")for(let[s,r]of Object.entries(e.shareLib)){let o={};if(o.module=s,typeof r=="string"){let p=r.match(this.exp)||[];p.length>0?(o.global=p[1],o.entry=p[2],o.type="js",t.push(o),o={}):(o.global="",o.entry=r,o.type="js",t.push(o),o={})}else Array.isArray(r)?r.map(p=>{if(!p)return;if(p.split("?")[0].endsWith(".css"))o.entry=p,o.type="css";else{let u=p.match(this.exp)||[];u.length>0?(o.global=u[1],o.entry=u[2],o.type="js"):(o.global="",o.entry=p,o.type="js")}t.push(o),o={}}):typeof r=="object"&&r.entry&&(o.entry=r.entry,o.global=r.global,o.type=r.type,t.push(o),o={})}await Promise.all([this.setExternalAssets(t)])}async setExternalAssets(e=[]){if(e.length>0){let t=[];t=t.concat(e),t.map(s=>{s.type=s.type||"js",s.type==="js"&&s.module?(s.global?this.externals[s.module]=s.global:n.empConfig.isESM&&(this.useImportMap?(this.externals[s.module]=s.module,this.importMap.imports[s.module]=s.entry):this.externals[s.module]=s.entry),s.entry&&!n.empConfig.isESM&&this.externalAssets.js.push(s.entry)):s.type==="css"&&s.entry&&this.externalAssets.css.push(s.entry)})}}}});import Ne from"url";import Je from"chalk";import{ip as Pt}from"address";import{gateway4sync as $t}from"default-gateway";var te,O,se=l(()=>{"use strict";te=class{imf={protocol:"",port:8e3,pathname:"/"};host="0.0.0.0";urls={lanUrlForConfig:"",lanUrlForTerminal:Je.gray("unavailable"),localUrlForTerminal:"",localUrlForBrowser:""};setup(e){e.host&&(this.host=e.host),e.protocol&&(this.imf.protocol=e.protocol),e.pathname&&(this.imf.pathname=e.pathname),e.port&&(this.imf.port=e.port),this.setupUrls()}setupUrls(){let{host:e}=this,t=e==="0.0.0.0"||e==="::",s;if(t){s="localhost";try{this.urls.lanUrlForConfig=this.getLanIp(),this.urls.lanUrlForConfig&&(/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(this.urls.lanUrlForConfig)?this.urls.lanUrlForTerminal=this.prettyPrintUrl(this.urls.lanUrlForConfig):this.urls.lanUrlForConfig="")}catch{}}else s=e,this.urls.lanUrlForConfig=e,this.urls.lanUrlForTerminal=this.prettyPrintUrl(this.urls.lanUrlForConfig);this.urls.localUrlForTerminal=this.prettyPrintUrl(s),this.urls.localUrlForBrowser=this.formatUrl(s)}getLanIp(){let{int:e}=$t();return Pt(e||"")||"127.0.0.1"}formatUrl(e){let{protocol:t,port:s,pathname:r}=this.imf;return Ne.format({protocol:t,hostname:e,port:s,pathname:r})}prettyPrintUrl(e){let{protocol:t,port:s,pathname:r}=this.imf;return Ne.format({protocol:t,hostname:e,port:Je.bold(s),pathname:r})}},O=new te});var ie,A,re=l(()=>{"use strict";se();y();g();ie=class{isADB=!1;isHttps=!1;get isHttpBase(){let e=n.empOptions.base||"";return e.indexOf("http://")>-1||e.indexOf("https://")>-1}setup(){if(this.isADB=!!n.empOptions.autoDevBase&&n.mode==="development"&&!this.isHttpBase,!this.isADB)return;let{server:e,https:t}=n.empOptions.server||{};this.isHttps=e==="https"||typeof e=="object"&&e.type==="https"||t===!0;let s=O.getLanIp(),r=this.isHttps?"https":"http",o=n.empOptions.server?.port||8e3;n.empOptions.base=`${r}://${s}:${o}/`,n.empOptions.server=f({port:o,client:{webSocketURL:`${this.isHttps?"wss":"ws"}://${s}:${o}/ws`}},n.empOptions.server)}},A=new ie});var F,Ve=l(()=>{"use strict";re();g();Q();F=class{op={};constructor(e={}){this.op=e}async afterGetEmpOptions(){A.setup(),this.op.afterGetEmpOptions&&await this.op.afterGetEmpOptions()}async beforePlugin(){n.empConfig.build.polyfill==="entry"&&n.chain.plugin("empPolyfill").use(L),this.op.beforePlugin&&await this.op.beforePlugin()}async afterPlugin(){this.op.afterPlugin&&await this.op.afterPlugin()}async beforeBuild(){this.op.beforeBuild&&await this.op.beforeBuild()}async afterBulid(){this.op.afterBulid&&await this.op.afterBulid()}async beforeDevServe(){console.log(this.op),this.op.beforeDevServe&&await this.op.beforeDevServe()}async afterDevServe(){this.op.afterDevServe&&await this.op.afterDevServe()}async beforeServe(){this.op.beforeServe&&await this.op.beforeServe()}async afterServe(){this.op.afterServe&&await this.op.afterServe()}}});import kt from"node:fs";var oe,_e,We=l(()=>{"use strict";y();Ue();Ve();oe=class{store;appSrc="src";appEntry="";base="";target=[];assign(e,t){return t=t||{},f(e,t)}empShareLib=new M;isESM=!1;async autoDevSet(){this.store.mode==="development"&&this.store.empOptions.autoDevBase}checkIsESM(e){return["es3","es5"].indexOf(e)===-1}lifeCycle;async setup(e){this.store=e,await this.syncEmpOptions(),this.lifeCycle=new F(this.store.empOptions.lifeCycle),await this.lifeCycle.afterGetEmpOptions(),this.isESM=this.checkIsESM(this.build.target),this.store.empOptions.target?(this.target=this.store.empOptions.target,Array.isArray(this.target)&&!this.target.includes(this.build.target)&&this.target.push(this.build.target)):this.target=["web",this.build.target];let{appSrc:t,base:s,appEntry:r}=this.store.empOptions;t&&(this.appSrc=t),s&&(this.base=s),r&&(this.appEntry=r),this.store.empConfig.empShare&&await this.empShareLib.setup()}async chain(){this.store.empOptions.chain&&await this.store.empOptions.chain(this.store.chain)}async plugins(){let e=[];this.store.empOptions.plugins&&Array.isArray(this.store.empOptions.plugins)&&this.store.empOptions.plugins.length>0&&(this.store.empOptions.plugins.map(t=>{e.push(t.rsConfig(this.store))}),await Promise.all(e))}get debug(){return this.assign({loggerLevel:"info",clearLog:!0,progress:!0,showRsconfig:!1,showPerformance:!1,rspackCache:!0,infrastructureLogging:{appendOnly:!0,level:"warn"}},this.store.empOptions.debug)}get build(){let e=this.store.empOptions.build?.staticDir?`${this.store.empOptions.build?.staticDir}/`:"";return this.assign({outDir:"dist",staticDir:e,assetsDir:"assets",publicDir:"public",chunkIds:this.store.isDev?"named":"deterministic",moduleIds:this.store.isDev?"named":"deterministic",sourcemap:!0,minify:!this.store.isDev,minOptions:{},target:"es5",polyfill:!1,externalHelpers:!1,browserslist:this.store.browserslistOptions.default},{...this.store.empOptions.build,staticDir:e})}get html(){let e=this.store.empOptions.html?.template?[]:{charset:{charset:"utf-8"},"http-equiv":{"http-equiv":"X-UA-Compatible",content:"IE=edge"},viewport:{content:"width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"},keywords:{keywords:""},description:{description:""}};return this.assign({lang:"zh-CN",title:"EMP",inject:"body",minify:!this.store.isDev,scriptLoading:this.isESM?"module":"defer",meta:e,files:{css:[],js:[]},tags:{headTags:[],bodyTags:[]}},this.store.empOptions.html)}get entries(){return this.store.empOptions.entries?this.store.empOptions.entries:{}}get react(){return this.assign({hmr:!0,svgr:!1},this.store.empOptions.react)}get server(){let e={host:"0.0.0.0",port:8e3,open:process.platform==="darwin",hot:!0,watchFiles:["src/**/*.html"],static:[{directory:this.store.publicDir,watch:this.store.isDev}],allowedHosts:["all"],historyApiFallback:!0,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, PATCH, OPTIONS","Access-Control-Allow-Headers":"X-Requested-With, content-type, Authorization"}};return this.assign(e,this.store.empOptions.server)}get empShare(){return this.assign({name:"",filename:"emp.js",shared:{},mfVersion:1.5},this.store.empOptions.empShare)}get css(){return this.assign({postcss:[]},this.store.empOptions.css)}get output(){let e=(this.store.isDev,".[contenthash:8]"),t=this.store.isDev?"":".[contenthash:8]",{assetsDir:s,staticDir:r}=this.store.empConfig.build,o={publicPath:this.store.empConfig.base?this.store.empConfig.base:"auto",crossOriginLoading:"anonymous",filename:`${r}js/[name]${e}.js`,cssFilename:`${r}css/[name]${t}.css`,cssChunkFilename:`${r}css/[name]${t}.css`,assetModuleFilename:`${r}${s}/[name]${e}[ext][query]`,path:this.store.outDir,clean:!0};return this.assign(o,this.store.empOptions.output)}get define(){let e={mode:this.store.mode,env:this.store.cliOptions.env};return this.store.empOptions.define&&(e={...e,...this.store.empOptions.define}),this.setDefine(e)}setDefine(e){let t=this.store.empOptions.defineFix?this.store.empOptions.defineFix:this.isESM?"esm":"cjs",s={};return Object.keys(e).map(r=>{(t==="all"||t==="esm")&&(s[`import.meta.env.${r}`]=JSON.stringify(e[r])),(t==="all"||t==="cjs")&&(s[`process.env.${r}`]=JSON.stringify(e[r])),s[`${r}`]=JSON.stringify(e[r])}),s}get externals(){return this.assign(this.empShareLib.externals,this.store.empOptions.externals)}get resolve(){return f({alias:{src:this.store.resolve("src"),"@":this.store.resolve("src")},extensions:["...",".js",".jsx",".mjs",".ts",".tsx",".css",".less",".scss",".sass",".json",".wasm",".vue",".svg",".svga"]},this.store.empOptions.resolve)}async syncEmpOptions(){let e=this.store.resolve("emp-config.js");if(!kt.existsSync(e))return;let{default:t}=await import(this.store.importFileUrl(e));typeof t=="function"?this.store.empOptions=await t(this.store):this.store.empOptions=t||{}}get moduleTransformRule(){let{moduleTransform:e}=this.store.empOptions,t=this.assign({defaultExclude:!1},e),s={and:[],not:[]};return t.defaultExclude===!0&&s.and.push(/(node_modules|bower_components)/),t?.exclude&&(s.and=s.and.concat(t.exclude)),e?.include&&(s.not=t.include),s}get cacheDir(){return this.store.empOptions.cacheDir?this.store.empOptions.cacheDir:"node_modules/.emp-cache"}get reactRuntime(){if(this.store.reactVersion)return this.store.empOptions.reactRuntime?this.store.empOptions.reactRuntime:T(this.store.reactVersion,"17")>-1?"automatic":"classic"}},_e=new oe});import v from"node:path";import jt from"node:fs/promises";import Tt from"webpack-chain";import{pathToFileURL as Rt}from"node:url";import Dt from"node:util";var ne,n,g=l(()=>{"use strict";_();He();b();We();y();ne=class{empPkg={dependencies:{},devDependencies:{},version:"2.0.0",name:""};pkg={dependencies:{},devDependencies:{},version:"0.0.0",name:""};root=process.cwd();empRoot=Ce;empSource=v.resolve(this.empRoot,"dist");resolve=e=>v.isAbsolute(e)?e:v.resolve(this.root,e);empResolve=e=>v.resolve(this.empRoot,e);appSrc="";outDir="";publicDir="";resource={dir:"",key:"",cert:""};cacheDir="";mode="development";cliMode="dev";isDev=!0;reactVersion=void 0;cliOptions;chain;rsConfig;empOptions={};empConfig;async setup(e,t){await this.initVars(e,t),this.empConfig=_e,await this.empConfig.setup(this),this.initPaths(),this.chain=new Tt,await Ie.setup(this),this.setLogger(),this.toConfig(),this.logConfig()}async initVars(e,t){this.cliOptions=t||{},this.cliMode="prod",this.mode=e==="dev"?"development":"production",this.isDev=this.mode==="development";let s=await V(this.empResolve("package.json")),r=await V(this.resolve("package.json"));this.empPkg={...this.empPkg,...s},this.pkg={...this.pkg,...r},this.reactVersion=this.pkg.dependencies.react||this.pkg.devDependencies.react}initPaths(){this.appSrc=this.resolve(this.empConfig.appSrc),this.outDir=this.resolve(this.empConfig.build.outDir),this.publicDir=this.resolve(this.empConfig.build.publicDir),this.cacheDir=this.resolve(this.empConfig.cacheDir),this.resource.dir=v.join(this.empRoot,"resource"),this.resource.cert=v.join(this.resource.dir,"emp.cert"),this.resource.key=v.join(this.resource.dir,"emp.key")}setLogger(){let e=this.cliMode==="dev"?"debug":"info";this.empConfig.debug.loggerLevel&&(e=this.empConfig.debug.loggerLevel),a.setup({pname:`EMP\u26A1${this.empPkg.version}${this.cliMode==="dev"?".DEV":""}`,logLevel:e})}merge(e){this.chain.merge(e)}importResolve(e,t){return ve(e,t)}importFileUrl(e){return Rt(e).toString()}toConfig(){this.rsConfig=this.chain.toConfig()}logConfig(){if(this.empConfig.debug.showRsconfig)if(typeof this.empConfig.debug.showRsconfig=="string"){let e=v.join(this.root,this.empConfig.debug.showRsconfig);jt.writeFile(e,JSON.stringify(this.rsConfig,null,2))}else{let e={colors:!0,depth:null},t=typeof this.empConfig.debug.showRsconfig=="object"?f(e,this.empConfig.debug.showRsconfig):e;console.log(a.link("[Compile Config]")),console.log(Dt.inspect(this.rsConfig,t))}}get browserslistOptions(){return{default:["chrome >= 87","edge >= 88","firefox >= 78","safari >= 14"],h5:["iOS >= 9","Android >= 4.4","last 2 versions","> 0.2%","not dead"],node:["node >= 20"]}}},n=new ne});import{exec as Lt}from"node:child_process";import{promisify as Mt}from"node:util";var qe,Xe,At,Ft,Qe,Ye=l(()=>{"use strict";b();g();qe=Mt(Lt),Xe=["Google Chrome Canary","Google Chrome Dev","Google Chrome Beta","Google Chrome","Microsoft Edge","Brave Browser","Vivaldi","Chromium"],At=async()=>{let i=process.env.BROWSER;if(!i||!Xe.includes(i)){let{stdout:e}=await qe("ps cax");i=Xe.find(t=>e.includes(t))}return i},Ft=async i=>{if(process.platform==="darwin")try{let t=await At();if(t){let s=`osascript openChrome.applescript "${encodeURI(i)}" "${t}"`;return await qe(s,{cwd:n.resource.dir}),!0}}catch(t){a.debug(t)}try{let{default:t}=await import("open");return await t(i),!0}catch(t){return a.error("Failed to open start URL."),a.error(t),!1}},Qe=Ft});import Bt from"net";import zt from"os";async function Ke(i,e="localhost"){if(i!==Gt&&(i<Ze||i>pe))throw new Error(`Port number must lie between ${Ze} and ${pe}`);let t=i,s=It(),r;e&&!s.has(e)?r=new Set([e]):r=s;let o=new Set(["EADDRINUSE","EACCES"]);for(;t<=pe;)try{return await Ut(t,r)}catch(p){if(!o.has(p.code))throw p;t+=1}throw new Error("No available ports found")}var Ze,pe,Gt,It,Ht,Ut,et=l(()=>{"use strict";Ze=1024,pe=65535,Gt=443,It=()=>{let i=zt.networkInterfaces(),e=new Set([void 0,"0.0.0.0"]);for(let t of Object.values(i))if(t)for(let s of t)e.add(s.address);return e},Ht=(i,e)=>new Promise((t,s)=>{let r=Bt.createServer();r.unref(),r.on("error",s),r.listen(i,e,()=>{let{port:o}=r.address();r.close(()=>{t(o)})})}),Ut=async(i,e)=>{let t=new Set(["EADDRNOTAVAIL","EINVAL"]);for(let s of e)try{await Ht(i,s)}catch(r){if(!t.has(r.code))throw r}return i}});import tt from"node:fs/promises";import B from"chalk";var C,z=l(()=>{"use strict";b();g();y();se();Ye();et();re();C=class{sf={protocol:"http",host:"0.0.0.0",port:8e3,publicPath:"",publicHasHttp:!1,isOpenBrower:!1,url:"",urls:{localUrlForBrowser:"",localUrlForTerminal:"",lanUrlForTerminal:"",lanUrlForConfig:""}};async adaptServer(){this.sf.publicPath=n.rsConfig.output?.publicPath==="auto"?"/":n.rsConfig.output?.publicPath||"/",this.sf.isOpenBrower=!!n.empConfig.server.open,this.sf.protocol=this.isHttps?"https":"http",this.sf.host=n.empConfig.server.host?n.empConfig.server.host:this.sf.host,this.sf.port=n.empConfig.server.port,await this.serverPort(),O.setup(this.sf),this.sf.publicPath&&(this.sf.publicPath.indexOf("http://")>-1||this.sf.publicPath.indexOf("https://")>-1)?(this.sf.url=this.sf.publicPath,this.sf.publicHasHttp=!0,this.sf.urls.localUrlForTerminal=O.prettyPrintUrl("localhost")):(this.sf.urls=O.urls,this.sf.url=this.sf.urls.localUrlForBrowser)}startOpen(){let{urls:e}=this.sf;this.sf.publicHasHttp?(a.info(`${B.greenBright("\u279C")} Local: ${a.link(e.localUrlForTerminal)}`),a.info(`${B.greenBright("\u279C")} Network: ${a.link(this.sf.publicPath)}`)):(a.info(`${B.greenBright("\u279C")} Local: ${a.link(e.localUrlForTerminal)}`),a.info(`${B.greenBright("\u279C")} Network: ${a.link(e.lanUrlForTerminal)}
11
+ `)),this.sf.isOpenBrower&&Qe(this.sf.url)}async setup(e,t){await n.setup(e,t),n.empConfig.debug.clearLog&&Oe(),a.title(`${e}`),await this.adaptServer(),await this.run()}async run(){}get isHttps(){let{server:e,https:t}=n.empConfig.server||{};return e==="https"||typeof e=="object"&&e.type==="https"||t===!0}getcert(){return Promise.all([tt.readFile(n.resource.key),tt.readFile(n.resource.cert)])}async serverPort(){if(A.isADB)return;let{port:e,host:t}=this.sf,s=await Ke(e,t);s!==e&&(this.sf.port=s,n.rsConfig.devServer?.port&&(n.rsConfig.devServer.port=s))}}});import d from"chalk";import w from"node:path";import{gzipSizeSync as Nt}from"gzip-size";import Jt from"node:fs";function Yt(i,e){let t=[i,e],s=["File","Size","Gzipped"].reduce((r,o,p)=>{let c=t[p],u=o;return c&&(u=o.length<c?o+" ".repeat(c-o.length):o),`${r+u} `}," ");console.log(d.bold.blue(s))}async function st(i){let e=i.toJson({all:!1,assets:!0,timings:!0});k(e.time);let s=e.assets.filter(m=>Xt(m.name)).map(Qt);s.sort((m,$)=>m.size-$.size);let r=Math.max(...s.map(m=>m.sizeLabel.length)),o=Math.max(...s.map(m=>(m.folder+w.sep+m.name).length));Yt(o,r);let p=0,c=0;s.forEach(m=>{let{sizeLabel:$}=m,{name:ht,folder:ft,gzipSizeLabel:ut}=m,ue=(ft+w.sep+ht).length,ge=$.length;if(p+=m.size,c+=m.gzippedSize,ge<r){let U=" ".repeat(r-ge);$+=U}let de=d.gray(m.folder+w.sep)+Zt(m.name);if(ue<o){let U=" ".repeat(o-ue);de+=U}a.info(` ${de} ${d.gray($)} ${ut}`)});let u=`${d.bold.blue("Total size:")} ${G(p)}`,P=`${d.bold.blue("Gzipped size:")} ${G(c)}`;a.info(`
12
+ ${u}
13
+ ${P}
14
+ `)}function k(i=0){a.info(`${d.greenBright("\u2713")} Ready in ${Pe(Number(i))}`)}var Vt,_t,Wt,Xt,qt,Qt,G,Zt,I=l(()=>{"use strict";g();b();y();Vt=/\.html$/,_t=/\.(?:js|mjs|cjs|jsx)$/,Wt=/\.css$/,Xt=i=>!/\.map$/.test(i)&&!/\.LICENSE\.txt$/.test(i),qt=i=>i>300*1e3?d.red:i>100*1e3?d.yellow:d.white,Qt=i=>{let e=i.name.split("?")[0],t=G(i.size),s=w.basename(e),r=w.join(w.basename(n.empConfig.build.outDir),w.dirname(e)),o=Jt.readFileSync(w.join(n.empConfig.build.outDir,e)),p=o.length,c=Nt(o),u=qt(c)(G(c));return{size:p,folder:r,name:s,gzippedSize:c,sizeLabel:t,gzipSizeLabel:u}};G=i=>{let e=i/1e3;return`${e.toFixed(e<1?2:1)} kB`},Zt=i=>_t.test(i)?d.yellowBright(i):Wt.test(i)?d.greenBright(i):Vt.test(i)?d.blueBright(i):d.magenta(i)});var it={};N(it,{default:()=>ts});import{rspack as Kt}from"@rspack/core";import{RspackDevServer as es}from"@rspack/dev-server";var ae,ts,rt=l(()=>{"use strict";g();z();b();y();I();ae=class extends C{async run(){let e=f(n.rsConfig,{stats:{all:!1,colors:!0,assets:!1,chunks:!1,entrypoints:!1,timings:!1,version:!1,errors:!0,warnings:!0},devServer:{open:!1,setupExitSignals:!0}}),t=Kt(e);if(!n.rsConfig.devServer){a.error("devServer is not defined in config");return}let s=Object.assign({},n.rsConfig.devServer);if(this.isHttps&&(s.https===!0&&delete s.https,!s.server)){let[p,c]=await this.getcert();s.server={type:"https",options:{key:p,cert:c}}}let r=new es(s,t);this.startOpen(),n.empConfig.lifeCycle.beforeDevServe&&await n.empConfig.lifeCycle.beforeDevServe(),await r.start();let o=p=>{let c=p?.toJson({all:!1,colors:!1,assets:!1,chunks:!1,timings:!0});k(c.time)};n.empConfig.debug.showPerformance&&t.hooks.afterDone.tap("done",o),r.middleware?.waitUntilValid(p=>{n.empConfig.debug.showPerformance||o(p),n.empConfig.lifeCycle.afterDevServe&&n.empConfig.lifeCycle.afterDevServe()})}},ts=new ae});var ot={};N(ot,{default:()=>is});import{rspack as ss}from"@rspack/core";var le,is,nt=l(()=>{"use strict";b();g();z();I();le=class extends C{async run(){n.empConfig.lifeCycle.beforeBuild&&await n.empConfig.lifeCycle.beforeBuild(),ss(n.rsConfig,async(e,t)=>{if(e!==null){a.error(e.stack||e),e.message&&a.error(e.message);return}if(!t){a.red("Stats is Undefined.");return}t.hasErrors()&&(a.error(t.toString({colors:!0,children:!0})),a.red("Failed to compile."),process.exit(1)),t.hasWarnings()&&(a.yellow("Compiled with warnings."),a.warn(t.toString({colors:!0,children:!0}))),await st(t),n.empConfig.lifeCycle.afterBulid&&await n.empConfig.lifeCycle.afterBulid()})}},is=new le});import rs from"express";import os from"cors";import ns from"compression";import ps from"https";var H,pt=l(()=>{"use strict";z();H=class extends C{app;async init(){let e=rs();e.use(ns()),e.use(os()),this.app=e}async server(){if(this.isHttps){let[e,t]=await this.getcert();ps.createServer(typeof this.isHttps!="boolean"?this.isHttps:{key:e,cert:t},this.app).listen(this.sf.port,async()=>{this.startOpen(),await this.onReady()})}else this.app.listen(this.sf.port,async()=>{this.startOpen(),await this.onReady()})}async onReady(){}async middleware(){}async start(){await this.init(),await this.middleware(),await this.server()}}});var at={};N(at,{default:()=>hs});import as from"express";import ls from"path";import cs from"node:fs/promises";import ms from"node:fs";var ce,hs,lt=l(()=>{"use strict";pt();g();b();I();ce=class extends H{timing=0;async run(){if(this.timing=Date.now(),!ms.existsSync(n.outDir))return a.sysError(`emp serve must be executed after emp build,${n.outDir} not exist!`);n.empConfig.lifeCycle.beforeServe&&await n.empConfig.lifeCycle.beforeServe(),this.start()}async middleware(){let e=n.resolve(n.rsConfig.output?.path);this.app.use(as.static(e));let t=await cs.readFile(ls.join(e,"index.html"),"utf8");this.app.get("*",(s,r)=>r.send(t))}async onReady(){k(Date.now()-this.timing),n.empConfig.lifeCycle.afterServe&&await n.empConfig.lifeCycle.afterServe()}},hs=new ce});g();g();y();b();import{program as x}from"commander";import me,{exit as fs}from"node:process";function ct(){let i="20.0.0";T(i,me.versions.node)===1&&(a.sysError(`\u5F53\u524D\u7248\u672C\u4E3Av${me.versions.node} \u6700\u4F4E\u8981\u6C42\u4E3Av${i}`),fs(0)),x.version(n.empPkg.version,"-v, --version").usage("<command> [options]"),x.command("dev").description("Dev \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-h, --hot","\u662F\u5426\u4F7F\u7528\u70ED\u66F4\u65B0 \u9ED8\u8BA4\u542F\u52A8").option("-o, --open","\u662F\u5426\u6253\u5F00\u8C03\u8BD5\u9875\u9762 \u9ED8\u8BA4\u4E0D\u6253\u5F00").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").option("-ev, --env-vars <key=value>","\u5B9A\u4E49\u4E00\u4E2A\u73AF\u5883\u53D8\u91CF -ev key=value \u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u91CD\u590D\u8C03\u7528 -ev key=value -ev key=value",(e,t)=>{let[s,r]=e.split("=");return t[s]=r,t},{}).action(async e=>{let{default:t}=await Promise.resolve().then(()=>(rt(),it));await t.setup("dev",e)}),x.command("build").description("Build \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-a, --analyze","\u751F\u6210\u5206\u6790\u62A5\u544A \u9ED8\u8BA4\u4E3A false").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").option("-ev, --env-vars <key=value>","\u5B9A\u4E49\u4E00\u4E2A\u73AF\u5883\u53D8\u91CF -ev key=value \u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u91CD\u590D\u8C03\u7528 -ev key=value -ev key=value",(e,t)=>{let[s,r]=e.split("=");return t[s]=r,t},{}).action(async e=>{let{default:t}=await Promise.resolve().then(()=>(nt(),ot));await t.setup("build",e)}),x.command("serve").description("Server \u6A21\u5F0F").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async e=>{let{default:t}=await Promise.resolve().then(()=>(lt(),at));await t.setup("serve",e)}),x.command("dts").description("\u62C9\u53D6 remote \u9879\u76EE\u7684 d.ts").option("-p, --typingsPath <typingsPath>","\u4E0B\u8F7D\u76EE\u5F55").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").action(e=>{}),x.command("init").description("\u521D\u59CB\u5316 emp \u9879\u76EE").option("-d, --data [data]","JSON\u6570\u636E http\u5730\u5740 \u6216\u8005 \u6587\u4EF6\u8DEF\u5F84\u76F8\u5BF9\u3001\u7EDD\u5BF9\u8DEF\u5F84").action(e=>{}),x.parse(me.argv)}g();import us from"fast-glob";import mt from"node:fs/promises";import he from"node:path";var gs=/(?:(?:import|export)\s?(?:type)?\s?(?:(?:\{[^;\n]+\})|(?:[^;\n]+))\s?from\s?['"][^;\n]+['"])|(?:import\(['"][^;\n]+?['"]\))/g,ds=/(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)['"]/,ys=/import\(['"]([^;\n]+?)['"]\)/,fe=class{list=[];outDir=n.resolve("dist");aliasName="@empjs/cli";async setup(e,t){e&&(this.outDir=e),t&&(this.aliasName=t);let s=await this.readDts();await this.writeCode(s)}async readDts(){this.list=await us([`${n.empConfig.build.outDir}/**/*.d.ts`]);let e=[];this.list.map(s=>{s=n.resolve(s),e.push(this.readFile(s))});let t=await Promise.all(e);return t=t.map(s=>this.replaceAliasPath(s)),t}async readFile(e){let t=await mt.readFile(e,{encoding:"utf-8"});return{src:e,code:t}}replaceAliasPath({src:e,code:t}){t=t.replace(gs,r=>{let o=r.match(ds);if(o||(o=r.match(ys)),o&&o[1]){let p=o[1];if(!p.startsWith("."))return r;let c=he.resolve(he.dirname(e),p).replace(this.outDir,this.aliasName);return r.replace(o[1],c)}return r});let s=e.replace(this.outDir,this.aliasName).replace(".d.ts","");return s.endsWith("/index")&&(s=s.replace("/index","")),t=this.warpDeclareModule(s,t),{code:t,src:e,mod:s}}warpDeclareModule(e,t){return`declare module '${e}' {\r
15
+ ${t}}\r
16
+ `}async writeCode(e){let t="";e.map(s=>{t+=s.code}),await mt.writeFile(he.join(this.outDir.replace("dist","types"),"type.d.ts"),t)}},bs=new fe;function qr(i){return i}export{qr as defineConfig,bs as dts,ct as runScript,n as store};
@@ -1,7 +0,0 @@
1
- import { HttpServer } from './httpBase';
2
- declare class ServeScript extends HttpServer {
3
- run(): Promise<void>;
4
- middleware(): Promise<void>;
5
- }
6
- declare const _default: ServeScript;
7
- export default _default;
@@ -1,7 +1,8 @@
1
1
  import { GlobalStore } from '../store';
2
- import { BuildType, DebugType, EMPShareType, HtmlType, LifeCycle, ReactType, RsTarget, ServerType } from '../types/config';
2
+ import { BuildType, DebugType, EMPShareType, HtmlType, ReactType, RsTarget, ServerType } from '../types/config';
3
3
  import { Output } from '@rspack/core';
4
4
  import { EMPShareLib } from '../store/empShareLib';
5
+ import { LifeCycle } from '../store/lifeCycle';
5
6
  export declare class EmpConfig {
6
7
  private store;
7
8
  /**
@@ -32,6 +33,7 @@ export declare class EmpConfig {
32
33
  isESM: boolean;
33
34
  autoDevSet(): Promise<void>;
34
35
  checkIsESM(target: string): boolean;
36
+ lifeCycle: LifeCycle;
35
37
  setup(store: GlobalStore): Promise<void>;
36
38
  chain(): Promise<void>;
37
39
  plugins(): Promise<void>;
@@ -55,7 +57,6 @@ export declare class EmpConfig {
55
57
  syncEmpOptions(): Promise<void>;
56
58
  get moduleTransformRule(): any;
57
59
  get cacheDir(): string;
58
- get lifeCycle(): LifeCycle;
59
60
  get reactRuntime(): "automatic" | "classic" | undefined;
60
61
  }
61
62
  declare const _default: EmpConfig;
@@ -16,6 +16,7 @@ export declare class EMPShareLib {
16
16
  config: EMPShareType;
17
17
  importMap: ImportMapType;
18
18
  version: EMPShareType['mfVersion'];
19
+ isEmpshare: boolean;
19
20
  setup(): Promise<void>;
20
21
  /**
21
22
  * 是否取用 importMap
@@ -108,6 +108,11 @@ export declare class GlobalStore {
108
108
  * 打印 config
109
109
  */
110
110
  logConfig(): void;
111
+ get browserslistOptions(): {
112
+ default: string[];
113
+ h5: string[];
114
+ node: string[];
115
+ };
111
116
  }
112
117
  declare const _default: GlobalStore;
113
118
  export default _default;
@@ -0,0 +1,14 @@
1
+ export type LifeCycleType = Partial<LifeCycle>;
2
+ export declare class LifeCycle {
3
+ op: LifeCycleType;
4
+ constructor(op?: LifeCycleType);
5
+ afterGetEmpOptions(): Promise<void>;
6
+ beforePlugin(): Promise<void>;
7
+ afterPlugin(): Promise<void>;
8
+ beforeBuild(): Promise<void>;
9
+ afterBulid(): Promise<void>;
10
+ beforeDevServe(): Promise<void>;
11
+ afterDevServe(): Promise<void>;
12
+ beforeServe(): Promise<void>;
13
+ afterServe(): Promise<void>;
14
+ }
@@ -0,0 +1,22 @@
1
+ import { HtmlType } from '../../types/config';
2
+ import { EMPShareLib } from '../empShareLib';
3
+ import { type Compiler } from '@rspack/core';
4
+ export declare const HtmlImportMapPluginName = "HtmlImportMapPlugin";
5
+ export declare class HtmlImportMapPlugin {
6
+ importMap: EMPShareLib['importMap'];
7
+ constructor(importMap: EMPShareLib['importMap']);
8
+ apply(compiler: any): void;
9
+ }
10
+ export declare const HtmlEmpShareLibPluginName = "HtmlEmpShareLibPlugin";
11
+ export declare class HtmlEmpShareLibPlugin {
12
+ files: {
13
+ css: string[];
14
+ js: string[];
15
+ };
16
+ constructor(files: HtmlType['files']);
17
+ apply(compiler: any): void;
18
+ }
19
+ export declare class EmpPolyfillPlugin {
20
+ constructor();
21
+ apply(compiler: Compiler): void;
22
+ }
@@ -1,7 +1,16 @@
1
1
  import type { GlobalStore } from '../../store';
2
2
  declare class RspackModule {
3
3
  store: GlobalStore;
4
+ private swcJsOptions;
5
+ private swcTsOptions;
6
+ private coreJs;
4
7
  setup(store: GlobalStore): Promise<void>;
8
+ private swcParser;
9
+ private get swcTransform();
10
+ private swcJsc;
11
+ private get swcCoreVersion();
12
+ private swcOptions;
13
+ swcInitOptions(): void;
5
14
  scripts(): Promise<void>;
6
15
  react(): Promise<void>;
7
16
  files(): Promise<void>;
@@ -5,12 +5,15 @@ import Chain from 'webpack-chain';
5
5
  import { Externals, HtmlRspackPluginOptions, ModuleFederationPluginOptions, Output, Resolve, RuleSetRule, SwcJsMinimizerRspackPluginOptions } from '@rspack/core';
6
6
  import { EMP3PluginType } from './plugin';
7
7
  import { InspectOptions } from 'node:util';
8
+ import type { LifeCycle } from '../store/lifeCycle';
8
9
  export type LoggerType = 'debug' | 'info' | 'warn' | 'error';
9
10
  export type DebugType = {
10
11
  loggerLevel: LoggerType;
11
12
  clearLog: boolean;
12
13
  progress: boolean;
13
14
  showRsconfig: boolean | string | InspectOptions;
15
+ showPerformance: boolean;
16
+ rspackCache: boolean;
14
17
  /**
15
18
  * 是否显示执行日志
16
19
  * @default false
@@ -60,6 +63,11 @@ export type BuildType = {
60
63
  * @default 'public'
61
64
  */
62
65
  publicDir?: string;
66
+ /**
67
+ * named 使用有意义、方便调试的内容当作模块 id。此选项会在开发环境下默认开启。
68
+ * deterministic 使用对模块标识符哈希后的数字当作模块 id,有益于长期缓存。此选项会在生产环境下默认开启。
69
+ */
70
+ moduleIds?: 'named' | 'deterministic';
63
71
  /**
64
72
  * chunkIds
65
73
  * @default named|deterministic
@@ -84,6 +92,21 @@ export type BuildType = {
84
92
  * 生成代码 参考 https://swc.rs/docs/configuring-swc#jsctarget
85
93
  */
86
94
  target?: JscTarget;
95
+ /**
96
+ * 注入兼容代码
97
+ * module federation 入口 建议使用 entry
98
+ * @default false
99
+ */
100
+ polyfill?: 'entry' | 'usage' | false;
101
+ /**
102
+ * @swc/helpers 外置
103
+ * @default false
104
+ */
105
+ externalHelpers: boolean;
106
+ /**
107
+ * 浏览器 兼容版本
108
+ */
109
+ browserslist: string[];
87
110
  };
88
111
  export type JscTarget = 'es3' | 'es5' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022';
89
112
  export interface HtmlType extends HtmlRspackPluginOptions {
@@ -196,14 +219,6 @@ export type ExternalsItemType = {
196
219
  */
197
220
  type?: string;
198
221
  };
199
- export type LifeCycle = {
200
- afterBulid?: () => void;
201
- beforeBuild?: () => void;
202
- afterDevServe?: () => void;
203
- beforeDevServe?: () => void;
204
- afterServe?: () => void;
205
- beforeServe?: () => void;
206
- };
207
222
  export type RsTarget = RsConfig['target'];
208
223
  export type EmpOptions = {
209
224
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empjs/cli",
3
- "version": "3.0.0-beta.27",
3
+ "version": "3.0.0-beta.29",
4
4
  "description": "emp",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -69,7 +69,7 @@
69
69
  "@types/cors": "^2.8.12",
70
70
  "@types/default-gateway": "^7.2.1",
71
71
  "@types/express": "^4.17.13",
72
- "@types/fs-extra": "^9.0.13",
72
+ "@types/fs-extra": "^11.0.4",
73
73
  "@types/watchpack": "^2.4.3",
74
74
  "@types/webpack": "^5.28.4",
75
75
  "@types/webpack-bundle-analyzer": "^4.6.2",
@@ -81,10 +81,13 @@
81
81
  "tsc-alias": "^1.8.8"
82
82
  },
83
83
  "dependencies": {
84
- "@rspack/core": "0.5.8",
85
- "@rspack/dev-server": "0.5.8",
86
- "@rspack/plugin-react-refresh": "0.5.8",
84
+ "@module-federation/runtime": "^0.1.1",
85
+ "@module-federation/runtime-tools": "^0.1.1",
86
+ "@rspack/core": "0.5.9",
87
+ "@rspack/dev-server": "0.5.9",
88
+ "@rspack/plugin-react-refresh": "0.5.9",
87
89
  "@svgr/webpack": "^8.1.0",
90
+ "@swc/helpers": "^0.5.7",
88
91
  "@types/node": "^20.8.7",
89
92
  "@types/react": "^18.2.30",
90
93
  "address": "^2.0.1",
@@ -92,10 +95,12 @@
92
95
  "chalk": "^5.3.0",
93
96
  "commander": "^11.1.0",
94
97
  "compression": "^1.7.4",
98
+ "core-js": "^3.36.1",
95
99
  "cors": "^2.8.5",
96
100
  "default-gateway": "^7.2.2",
97
101
  "express": "^4.18.2",
98
102
  "fast-glob": "^3.3.1",
103
+ "fs-extra": "^11.2.0",
99
104
  "gzip-size": "^7.0.0",
100
105
  "html-entities": "^2.5.2",
101
106
  "html-webpack-plugin": "^5.6.0",
@@ -109,8 +114,6 @@
109
114
  "table": "^6.8.1",
110
115
  "typescript-plugin-css-modules": "^5.0.2",
111
116
  "webpack-bundle-analyzer": "^4.9.1",
112
- "webpack-chain": "^6.5.1",
113
- "webpack-dev-middleware": "^7.0.0",
114
- "webpack-hot-middleware": "^2.26.1"
117
+ "webpack-chain": "^6.5.1"
115
118
  }
116
- }
119
+ }
@@ -1,20 +1,14 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="<%= htmlWebpackPlugin.options.lang %>">
3
- <head>
4
- <!-- EMP inject title -->
5
- <title><%= htmlWebpackPlugin.options.title %></title>
6
- <meta name="keywords" content="<%= htmlWebpackPlugin.options.keywords %>" />
7
- <meta name="description" content="<%= htmlWebpackPlugin.options.description %>" />
8
- <!-- EMP inject css -->
9
- <% for (let i in htmlWebpackPlugin.options.files.css) { %>
10
- <link rel="stylesheet" href="<%= htmlWebpackPlugin.options.files.css[i] %>" />
11
- <% } %>
12
- </head>
13
- <body>
14
- <div id="emp-root"></div>
15
- <!-- EMP inject js -->
16
- <% for (let i in htmlWebpackPlugin.options.files.js) { %>
17
- <script src="<%= htmlWebpackPlugin.options.files.js[i] %>"></script>
18
- <% } %>
19
- </body>
20
- </html>
3
+
4
+ <head>
5
+ <title>
6
+ <%= htmlWebpackPlugin.options.title %>
7
+ </title>
8
+ </head>
9
+
10
+ <body>
11
+ <div id="emp-root"></div>
12
+ </body>
13
+
14
+ </html>
@@ -1,5 +0,0 @@
1
- declare class CycleRuntime {
2
- afterGetEmpOptions(): Promise<void>;
3
- }
4
- declare const _default: CycleRuntime;
5
- export default _default;
@@ -1,12 +0,0 @@
1
- declare class RuntimePlugins {
2
- constructor();
3
- beforeInit(): void;
4
- beforeLoadingRemote(): void;
5
- loadRemoteMatch(): void;
6
- loadRemote(): void;
7
- errorLoadRemote(): void;
8
- beforeLoadShare(): void;
9
- beforePreloadRemote(): void;
10
- }
11
- declare const _default: RuntimePlugins;
12
- export default _default;