@empjs/cli 4.0.0-alpha.1 → 4.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/346.js +3 -3
- package/dist/types/config.d.ts +16 -1
- package/package.json +4 -4
package/dist/346.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e from"node:module";let t=e.createRequire(import.meta.url);import s,{rspack as i}from"@rspack/core";import{program as o}from"commander";import r from"node:process";import n from"node:fs/promises";import a,{dirname as l}from"node:path";import p,{promisify as h}from"node:util";import c from"node:fs";import{createJiti as m}from"jiti";import u from"path";import*as g from"chalk";import{ip as d}from"address";import{gateway4sync as f}from"default-gateway";import v from"fs-extra";import y from"@empjs/chain";import{glob as
|
|
1
|
+
import e from"node:module";let t=e.createRequire(import.meta.url);import s,{rspack as i}from"@rspack/core";import{program as o}from"commander";import r from"node:process";import n from"node:fs/promises";import a,{dirname as l}from"node:path";import p,{promisify as h}from"node:util";import c from"node:fs";import{createJiti as m}from"jiti";import u from"path";import*as g from"chalk";import{ip as d}from"address";import{gateway4sync as f}from"default-gateway";import v from"fs-extra";import y from"@empjs/chain";import{glob as C}from"glob";import b from"html-webpack-plugin";import w from"fs";import{TsCheckerRspackPlugin as O}from"ts-checker-rspack-plugin";import P from"net";import k from"os";import j from"url";import{exec as x}from"node:child_process";import{fileURLToPath as $}from"node:url";var E,S={},N={};function D(e){var t=N[e];if(void 0!==t)return t.exports;var s=N[e]={exports:{}};return S[e](s,s.exports,D),s.exports}D.m=S,D.d=(e,t,s)=>{var i=(t,s)=>{for(var i in t)D.o(t,i)&&!D.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,[s]:t[i]})};i(t,"get"),i(s,"value")},D.add=function(e){Object.assign(D.m,e)};var A=D;D.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),D.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},E={346:0,410:0},D.C=e=>{var t,s,i=e.__rspack_esm_ids,o=e.__webpack_modules__,r=e.__rspack_esm_runtime,n=0;for(t in o)D.o(o,t)&&(D.m[t]=o[t]);for(r&&r(D);n<i.length;n++)s=i[n],D.o(E,s)&&E[s]&&E[s][0](),E[i[n]]=0},D.add({"@rsdoctor/rspack-plugin"(e){e.exports=t("@rsdoctor/rspack-plugin")}});var R={};D.r(R),D.d(R,{chalk:()=>z,color:()=>es,glob:()=>C,logger:()=>eo,utils:()=>L});var L={};D.r(L),D.d(L,{clearConsole:()=>em,deepAssign:()=>eu,ensureArray:()=>eg,getLanIp:()=>eh,getPkgVersion:()=>ec,importJsVm:()=>ey,jsonFilter:()=>ed,timeFormat:()=>ev,vCompare:()=>ef});var T=JSON.parse('{"rE":"4.0.0-alpha.2"}');async function _(){o.version(T.rE,"-v, --version").usage("<command> [options]"),o.command("dev").description("Dev 模式").option("-e, --env <env>","部署环境 dev、test、prod").option("-rd, --doctor","开启rsdoctor,可通过debug.rsdoctor操作").option("-h, --hot","是否使用热更新 默认启动").option("-o, --open","是否打开调试页面 默认不打开").option("-t, --ts","生成类型文件 默认为 false").option("-pr, --profile","统计模块消耗").option("-cl, --clearLog <clearLog>","清空日志 默认为 true").option("-ev, --env-vars <key=value>","定义一个环境变量 -ev key=value 多个环境变量重复调用 -ev key=value -ev key=value",(e,t)=>{let[s,i]=e.split("=");return t[s]=i,t},{}).action(async e=>{let{default:t}=await import("./dev.js");await t.setup("dev",e)}),o.command("build").description("Build 模式").option("-e, --env <env>","部署环境 dev、test、prod").option("-rd, --doctor","开启rsdoctor,可通过debug.rsdoctor操作").option("-a, --analyze","生成分析报告 默认为 false").option("-t, --ts","生成类型文件 默认为 false").option("-pr, --profile","统计模块消耗").option("-cl, --clearLog <clearLog>","清空日志 默认为 true").option("-w, --watch","watch 模式").option("-sv, --serve","watch 模式下启动serve").option("-ev, --env-vars <key=value>","定义一个环境变量 -ev key=value 多个环境变量重复调用 -ev key=value -ev key=value",(e,t)=>{let[s,i]=e.split("=");return t[s]=i,t},{}).action(async e=>{let{default:t}=await import("./build.js");await t.setup("build",e)}),o.command("serve").description("Server 模式").option("-cl, --clearLog <clearLog>","清空日志 默认为 true").option("-e, --env <env>","部署环境 dev、test、prod").option("-ev, --env-vars <key=value>","定义一个环境变量 -ev key=value 多个环境变量重复调用 -ev key=value -ev key=value",(e,t)=>{let[s,i]=e.split("=");return t[s]=i,t},{}).action(async e=>{let{default:t}=await import("./serve.js");await t.setup("serve",e)}),o.command("dts").description("拉取 remote 项目的 d.ts").option("-p, --typingsPath <typingsPath>","下载目录").option("-e, --env <env>","部署环境 dev、test、prod").action(e=>{}),o.command("init").description("初始化 emp 项目").option("-d, --data [data]","JSON数据 http地址 或者 文件路径相对、绝对路径").action(e=>{}),o.parse(r.argv)}var M=l($(import.meta.url)),U=$(import.meta.url);let F=function(e){let t=a.resolve(e);for(;;){let e=a.join(t,"package.json");if(c.existsSync(e))try{if("@empjs/cli"===JSON.parse(c.readFileSync(e,"utf8")).name)return t}catch{}let s=a.dirname(t);if(s===t)break;t=s}return a.resolve(M,U).replace(`${a.sep}dist${a.sep}index.js`,"")}(M),J=e=>"function"==typeof e&&"function"==typeof e.hex,z=(e=>{let t=e.default;if(J(t))return t;if(t&&"object"==typeof t){let e=t.default;if(J(e))return e}return e})(g),I=z.hex("#1abc9c"),H=z.hex("#16a085"),B=z.hex("#2ecc71"),V=z.hex("#27ae60"),W=z.hex("#e74c3c"),G=z.hex("#c0392b"),q=z.hex("#f1c40f"),K=z.hex("#f39c12"),Q=z.hex("#3498db"),X=z.hex("#2980b9"),Y=z.hex("#ecf0f1"),Z=z.hex("#fd79a8"),ee=z.hex("#e84393"),et=z.hex("#7f8c8d"),es={lightGreen:I,green:H,lightCyan:B,cyan:V,lightRed:W,red:G,yellow:q,orange:K,lightBlue:Q,blue:X,white:Y,lightMagenta:Z,magenta:ee,gray:et};class ei{brandName="";fullName="";logLevel="info";isLogTime=!1;setup({brandName:e,logLevel:t,fullName:s}){this.brandName=` [${e}] `,this.fullName=` ${s} `,this.fullName=es.green.bold(this.fullName),t&&(this.logLevel=t)}time=(...e)=>this.isLogTime&&console.time(...e);timeEnd=(...e)=>this.isLogTime&&console.timeEnd(...e);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(`${es.lightBlue(this.brandName)}${es.blue(` ${e} `)}
|
|
2
2
|
`)};cyan=e=>{console.log(`${es.lightCyan(this.brandName)}${es.cyan(` ${e} `)}
|
|
3
3
|
`)};magenta=e=>{console.log(`${es.lightMagenta(this.brandName)}${es.magenta(` ${e} `)}
|
|
4
4
|
`)};green=e=>{console.log(`${es.lightGreen(this.brandName)}${es.green(` ${e} `)}
|
|
@@ -6,5 +6,5 @@ import e from"node:module";let t=e.createRequire(import.meta.url);import s,{rspa
|
|
|
6
6
|
`)};red=e=>{console.log(`${es.lightRed(this.brandName)}${es.red(` ${e} `)}
|
|
7
7
|
`)};sysError=e=>{console.log(`${es.lightRed(" System Error Tips ")}${es.red(` ${e} `)}
|
|
8
8
|
`)};link=e=>es.blue(e);title=e=>{console.log(`${this.fullName}${es.yellow.underline(`${e}`)}
|
|
9
|
-
`)}}let eo=new ei;var er=$(import.meta.url);let en=["emp-config.ts","emp-config.js","emp.config.ts","emp.config.js","emp-config.mjs","emp-config.cjs","emp-config.mts","emp-config.cts","emp.config.mjs","emp.config.cjs","emp.config.mts","emp.config.cts"],ea=m(er,{interopDefault:!0,fsCache:!0,moduleCache:!0,cacheVersion:T.rE}),el=async()=>{let e="store.getEmpConfigPath";eo.time(e);let t=en.map(e=>u.resolve(eI.root,e)),s=await Promise.all(t.map(e=>c.promises.access(e).then(()=>!0,()=>!1))),i=t.find((e,t)=>s[t]);return eo.timeEnd(e),i},ep=async()=>{let e=u.join(eI.root,"tsconfig.json");return await c.promises.access(e).then(()=>!0,()=>!1)||(e=void 0),e},eh=()=>{let e="127.0.0.1";try{let{int:t}=f();return d(t||"")||e}catch(t){return e}},ec=e=>{try{let{version:t}=v.readJSONSync(e);return t}catch(e){return}};function em(){process.stdout.write("win32"===process.platform?"\x1b[2J\x1b[0f":"\x1b[2J\x1b[3J\x1b[H")}function eu(e,...t){for(let s of t)for(let t in s){let i=s[t],o=e[t];if(Object(i)==i&&Object(o)===o){e[t]=eu(o,i);continue}e[t]=s[t]}return e}let eg=e=>Array.isArray(e)?e:[e],ed=(e={},t=[])=>Object.keys(e).filter(e=>!t.includes(e)).reduce((t,s)=>(t[s]=e[s],t),{}),ef=(e="",t="")=>{let s=e.replace("^","").split("."),i=t.replace("^","").split("."),o=Math.max(s.length,i.length),r=0;for(let e=0;e<o;e++){let t=s.length>e?s[e]:0,o=isNaN(Number(t))?t.charCodeAt():Number(t),n=i.length>e?i[e]:0,a=isNaN(Number(n))?n.charCodeAt():Number(n);if(o<a){r=-1;break}if(o>a){r=1;break}}return r},ev=e=>{let t;if((e/=1e3)<1)return`${1e3*e} ms`;if(e<10){let t,s=e>=.01?2:3;return`${t=e.toFixed(s),I.bold(t)} s`}if(e<60){let t;return`${t=e.toFixed(1),I.bold(t)} s`}let s=e/60;return`${t=s.toFixed(2),I.bold(t)} m`},ey=e=>`data:text/javascript,${e}`,eb={rule:{mjs:"mjs",typescript:"typescript",javascript:"javascript",sourceMap:"sourceMapLoader",inline:"inline",raw:"raw",svg:"svg",image:"image",font:"fonts",svga:"svga",sass:"sass",less:"less",css:"css"},use:{swc:"swc",sourceMap:"sourceMapLoader",sass:"sassLoader",less:"lessLoader"},plugin:{tsCheckerRspackPlugin:"TsCheckerRspackPlugin",bundleAnalyzer:"bundleAnalyzerPlugin",define:"definePlugin",copy:"copyRspackPlugin",progress:"progressPlugin",html:{prefix:"html-plugin-"},rsdoctor:"rsdoctor",sourceMapDevTool:"sourceMapDevTool"},minimizer:{minJs:"minJs",minCss:"minCss"}};class eC{op={};constructor(e={}){this.op=e}async afterGetEmpOptions(){this.op.afterGetEmpOptions&&await this.op.afterGetEmpOptions()}async beforePlugin(){this.op.beforePlugin&&await this.op.beforePlugin()}async afterPlugin(){this.op.afterPlugin&&await this.op.afterPlugin()}async beforeModule(){this.op.beforeModule&&await this.op.beforeModule()}async afterModule(){this.op.afterModule&&await this.op.afterModule()}async beforeEmpPlugin(){this.op.beforeEmpPlugin&&await this.op.beforeEmpPlugin()}async afterEmpPlugin(){this.op.afterEmpPlugin&&await this.op.afterEmpPlugin()}async beforeBuild(){this.op.beforeBuild&&await this.op.beforeBuild()}async afterBulid(){this.op.afterBulid&&await this.op.afterBulid()}async beforeDevServe(){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()}}let ew=new class{store;appSrc="src";appEntry="";base="";target=[];assign(e,t){return eu(e,t=t||{})}get isESM(){return 1!==["es3","es5"].indexOf(this.store.empConfig.build.target)&&this.store.empConfig.build.useESM}lifeCycle;async setup(e){this.store=e,await this.syncEmpOptions(),await this.setupEmpOptions(),this.lifeCycle=new eC(this.store.empOptions.lifeCycle),await this.lifeCycle.afterGetEmpOptions(),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:i}=this.store.empOptions;t&&(this.appSrc=t),s&&(this.base=s),i&&(this.appEntry=i)}async setupEmpOptions(){await this.store.server.setupOnEmpOptionSync()}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(){let e=!1;return this.store.cliOptions.doctor&&(e={}),this.assign({loggerLevel:"info",clearLog:!0,progress:!0,showRsconfig:!1,showPerformance:!1,rsdoctor:e,infrastructureLogging:{appendOnly:!0,level:"warn"},newTreeshaking:this.store.empConfig.isESM,devShowAllLog:!1,showScriptDebug:!1,cssChunkingPlugin:!0,warnRuleAsWarning:!0},this.store.empOptions.debug)}get build(){let e=this.store.empOptions.build?.staticDir?`${this.store.empOptions.build?.staticDir}/`:"",t={js:this.store.isDev?"cheap-module-source-map":"source-map",css:!1};return this.store.empOptions.build?.sourcemap===!0&&(t.css=!0,t.js=this.store.isDev?"cheap-module-source-map":"source-map"),this.store.empOptions.build?.devtool&&(t.js=this.store.empOptions.build?.devtool),this.assign({outDir:"dist",staticDir:e,assetsDir:"assets",publicDir:"public",chunkIds:this.store.isDev?"named":"deterministic",moduleIds:this.store.isDev?"named":"deterministic",sourcemap:t,minify:!this.store.isDev,minOptions:{},cssminOptions:{},target:"es5",useESM:!1,polyfill:{mode:void 0,entryCdn:void 0,splitChunks:!1,include:[],coreJsFeatures:"stable",externalHelpers:!1,browserslist:this.store.browserslistOptions.default},swcConfig:{},devtool:this.store.isDev?"cheap-module-source-map":"source-map"},{...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:{name:"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,cache:!1!==this.cache,tags:[]},this.store.empOptions.html)}get entries(){return this.store.empOptions.entries?this.store.empOptions.entries:{}}get server(){let e={host:"0.0.0.0",port:8e3,open:"darwin"===process.platform,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"}};this.store.empOptions.server?.http2&&(this.store.server.httpsType="h2",delete this.store.empOptions.server.http2);let t=this.assign(e,this.store.empOptions.server),s="0.0.0.0"===t.host||"::"===t.host,{server:i}=this.store;if(this.store.isDev&&s&&i?.ip){let e=t.client??={};if(!e.webSocketURL){let s=i.isHttps?"wss":"ws",o=t.port??i.port??8e3;e.webSocketURL=`${s}://${i.ip}:${o}/ws`}}return t}get css(){return this.assign({sass:{mode:"modern",warnRuleAsWarning:this.store.empConfig.debug.warnRuleAsWarning},less:{lessOptions:{javascriptEnabled:!0,math:"always"}},prifixName:""},this.store.empOptions.css)}get output(){let e=(this.store.isDev,".[contenthash:8]"),t=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]${e}.js`,cssFilename:`${i}css/[name]${t}.css`,cssChunkFilename:`${i}css/[name]${t}.css`,assetModuleFilename:`${i}${s}/[name]${e}[ext][query]`,path:this.store.outDir,clean:!this.store.isDev,uniqueName:this.store.uniqueName};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)}get tsCheckerRspackPlugin(){let e={};return!!this.store.empOptions.tsCheckerRspackPlugin&&("object"==typeof this.store.empOptions.tsCheckerRspackPlugin&&(e=this.store.empOptions.tsCheckerRspackPlugin),this.assign({},e))}setDefine(e){let t=this.store.empOptions.defineFix?this.store.empOptions.defineFix:this.isESM?"esm":"cjs",s={};return Object.keys(e).map(i=>{"all"===t?(s[`import.meta.env.${i}`]=JSON.stringify(e[i]),s[`process.env.${i}`]=JSON.stringify(e[i])):"esm"===t?s[`import.meta.env.${i}`]=JSON.stringify(e[i]):"cjs"===t?s[`process.env.${i}`]=JSON.stringify(e[i]):"none"===t&&(s[`${i}`]=JSON.stringify(e[i]))}),s}get externals(){return this.assign({},this.store.empOptions.externals)}get resolve(){return eu({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="store.jiti.loadConfig.empConfig";if(eo.time(e),!this.store.rootPaths.empConfig)return;let{default:t}=await ea(this.store.rootPaths.empConfig);"function"==typeof t?this.store.empOptions=await t(this.store):this.store.empOptions=t||{},eo.timeEnd(e)}get moduleTransformRule(){let{moduleTransform:e}=this.store.empOptions,t=this.assign({defaultExclude:!1},e),s={and:[],not:[]};return!0===t.defaultExclude&&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 cache(){return!1!==this.store.empOptions.cache&&(this.store.empOptions.cache?this.store.empOptions.cache:"persistent")}get ignoreWarnings(){return this.store.empOptions.ignoreWarnings?this.store.empOptions.ignoreWarnings:[/Conflicting order/]}get autoPages(){let e;return this.store.empOptions.autoPages&&(e="boolean"==typeof this.store.empOptions.autoPages?{}:this.store.empOptions.autoPages,e=this.assign({path:"pages"},e)),e}showLogTitle(e){this.store.empOptions.showLogTitle?this.store.empOptions.showLogTitle(e):eo.title(`${e.cliAction}`)}},eO=new class{store;async setup(e){this.store=e;let t=[this.common(),this.stats(),this.devServer(),this.optimization(),this.checkTsconfig()];await Promise.all(t)}get cache(){let e;if(!1===this.store.empConfig.cache)return!1;let t={type:"persistent"===this.store.empConfig.cache?"persistent":"memory",buildDependencies:(e=[er],eI.rootPaths.pkg&&e.push(eI.rootPaths.pkg),eI.rootPaths.empConfig&&e.push(eI.rootPaths.empConfig),eI.rootPaths.tsConfig&&e.push(eI.rootPaths.tsConfig),e),version:this.store.empConfig.server.port?`${this.store.empPkg.version}_${this.store.empConfig.server.port}`:this.store.empPkg.version};return"object"==typeof this.store.empConfig.cache&&(t=this.store.deepAssign(t,this.store.empConfig.cache)),t}get name(){let e=this.store.empConfig.server.port?`_${this.store.empConfig.server.port}`:"";return this.store.pkg.name+e}async common(){this.store.merge({name:this.name,node:{global:!0},experiments:{nativeWatcher:!0,asyncWebAssembly:!0,css:!0},incremental:"advance-silent",lazyCompilation:this.store.isDev,target:this.store.empConfig.target,infrastructureLogging:this.store.empConfig.debug.infrastructureLogging,context:this.store.root,mode:this.store.mode,cache:this.cache,devtool:this.store.empConfig.build.sourcemap.js,output:{...this.store.empConfig.output,bundlerInfo:{force:!1},module:this.store.empConfig.output.module||this.store.empConfig.isESM},resolve:this.store.empConfig.resolve,externals:this.store.empConfig.externals,ignoreWarnings:this.store.empConfig.ignoreWarnings,watchOptions:{ignored:["**/node_modules/**","**/@mf-types/**"]}})}async checkTsconfig(){let e=this.store.resolve("tsconfig.json");if(await v.exists(e)){let t={};this.store.isOldRspack?t.tsConfigPath=e:t.tsConfig=e,this.store.merge({resolve:t})}}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:{}}};"entry"===this.store.empConfig.build.polyfill.mode&&this.store.empConfig.build.polyfill.splitChunks&&!this.store.empConfig.build.polyfill.entryCdn&&(e.splitChunks.cacheGroups.coreJs={test:/[\\/]node_modules[\\/](core-js)[\\/]/,name:"coreJs",chunks:"all",enforce:!0}),this.store.chain.merge({optimization:e})}},eP=new class{store;async setup(e){this.store=e;let t=[this.sass(),this.less(),this.css()];await Promise.all(t)}async sass(){let{rule:e,use:s}=this.store.chainName,i={},{sass:o}=this.store.empConfig.css;"modern"===o.mode&&(i.implementation=o.implementation?o.implementation:t.resolve("sass-embedded"),i.api="modern-compiler",i.sourceMap=this.store.empConfig.build.sourcemap.css,o.sassOptions&&(i.sassOptions=o.sassOptions)),void 0!==o.additionalData&&(i.additionalData=o.additionalData),void 0!==o.warnRuleAsWarning&&(i.warnRuleAsWarning=o.warnRuleAsWarning),void 0!==o.webpackImporter&&(i.webpackImporter=o.webpackImporter),this.store.chain.merge({module:{rule:{[e.sass]:{test:/\.(sass|scss)$/,use:{[s.sass]:{loader:t.resolve("sass-loader"),options:i}},type:"css/auto"}}}})}async less(){let{rule:e,use:s}=this.store.chainName,{lessOptions:i}=this.store.empConfig.css.less,o={loader:t.resolve("less-loader"),options:{lessOptions:i}};this.store.chain.merge({module:{rule:{[e.less]:{test:/\.less$/,use:{[s.less]:o},type:"css/auto"}}}})}async css(){let{rule:e}=this.store.chainName;this.store.chain.merge({module:{rule:{[e.css]:{test:/\.css$/,use:{},type:"css/auto"}}}})}};class ek{apply(e){let{webpack:t}=e;eI.empConfig.build.polyfill.entryCdn||new t.EntryPlugin(e.context,ey(`import 'core-js/${eI.empConfig.build.polyfill.coreJsFeatures}'`),{name:void 0}).apply(e)}}class ej{PluginName="HtmlEmpInjectPlugin";chunk="";files=[];constructor(e,t="",s=""){this.PluginName=`${this.PluginName}-${t}`,this.files=e,this.chunk=s}apply(e){e.hooks.compilation.tap(this.PluginName,e=>{C.getHooks(e).alterAssetTagGroups.tapPromise(this.PluginName,async e=>(this.chunk&&!e.plugin.userOptions.chunks?.includes(this.chunk)||this.files.map(t=>{let{pos:s,...i}=t;("body"===s?e.bodyTags:e.headTags).push({attributes:{},voidTag:!1,meta:{plugin:void 0},tagName:"script",...i})}),e))})}}let ex=new 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),this.prepareAndSetAsset(e),e}prepareAndSetAsset(e){let t=e.chunks?e.chunks[0]:void 0;this.store.injectTags(e.tags,t?`injectTags-${t}`:"injectTags",t),delete e.tags}injectPolyfill(){if(!this.store.empConfig.build.polyfill.entryCdn)return;let e=[{attributes:{src:this.store.empConfig.build.polyfill.entryCdn},tagName:"script",pos:"head"}];this.store.injectTags(e,"injectEMPPolyfill")}setChunk(e){return e.replace(a.extname(e),"").replace(`${this.store.empConfig.appSrc}${a.sep}`,"")}setTemplate(e){return e?this.store.resolve(e):this.store.empResolve(a.join("template","index.html"))}setFavicion(e){if(""!==e)return e?this.store.resolve(e):this.store.empResolve(a.join("template","favicon.ico"))}setEntryItem(e,t,s){s=s||this.store.resolve(a.join(this.store.empConfig.appSrc,e));let i=this.setChunk(e),o=[s];this.entriesConfig[i]={entry:{[i]:o},html:this.setHtmlConfig(t,[i])},this.store.entries[i]=o}setRspackHtmlPlugin(e,t){this.store.chain.plugin(`${this.store.chainName.plugin.html.prefix}${t}`).use(C,[e])}setRspackEntry(e){this.store.merge({entry:e})}async init(){this.injectPolyfill(),this.store.empConfig.autoPages?await this.setAutoPage():(await this.setDefaultEntry(),this.setEntryByConfig())}async setAutoPage(){eo.time("setAutoPage");let e=this.store.empConfig.autoPages?.path||"pages",t=a.join(this.store.appSrc,e),s=a.join(t,"**","*.{ts,tsx,jsx,js}"),i=await b([s],{windowsPathsNoEscape:!0});(i=i.map(e=>e.replace(`${t}${a.sep}`,""))).map(e=>{let s=this.store.empConfig.entries[e]||{};this.setEntryItem(e,{...this.store.empConfig.html,...s},a.join(t,e))}),eo.timeEnd("setAutoPage")}async setDefaultEntry(){let e="store.empConfig.setDefaultEntry";eo.time(e);let t=a.join(this.store.appSrc,this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index.{ts,tsx,jsx,js}"),s=await b([t],{windowsPathsNoEscape:!0});if(s[0]){let e=a.join(this.store.empConfig.appSrc,Object.keys(this.store.empConfig.entries).length>0&&this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index");this.setEntryItem(e,this.store.empConfig.html,s[0])}eo.timeEnd(e)}setEntryByConfig(){if(Object.keys(this.store.empConfig.entries).length>0)for(let[e,t]of Object.entries(this.store.empConfig.entries))this.setEntryItem(e,{...this.store.empConfig.html,...t})}toConfig(){for(let[e,t]of Object.entries(this.entriesConfig))this.setRspackHtmlPlugin(t.html,e),this.setRspackEntry(t.entry)}},e$=new class{store;swcJsOptions={};swcTsOptions={};coreJs={version:"3",alias:"",path:""};async setup(e){this.store=e,this.swcInitOptions(),await this.run()}async run(){let e=[this.jsDataUrl(),this.files(),this.scripts(),this.rspackGenerator(),this.rspackParser()];await this.store.empConfig.lifeCycle.beforeModule(),await Promise.all(e),await this.store.empConfig.lifeCycle.afterModule()}rspackGenerator(){let e=this.store.empConfig.css?.prifixName?`${this.store.empConfig.css?.prifixName}-`:"",t=this.store.isDev?`${e}[id]-[local]-[hash:base64:8]`:`${e}[local]-[hash:5]`;this.store.chain.merge({module:{generator:{"css/auto":{exportsConvention:"as-is",exportsOnly:!1,localIdentName:t,esModule:!0},css:{exportsOnly:!1,esModule:!0},"css/module":{exportsConvention:"as-is",exportsOnly:!1,localIdentName:t,esModule:!0},json:{JSONParse:!0}}}})}rspackParser(){this.store.chain.merge({module:{parser:{javascript:{dynamicImportMode:"lazy",dynamicImportPrefetch:!1,dynamicImportPreload:!1,url:!0,importMeta:!0},css:{namedExports:!1},"css/auto":{namedExports:!1},"css/module":{namedExports:!1}}}})}get isPolyfill(){return!!this.store.empConfig.build.polyfill.mode}swcParser(e){switch(e){case"js":return{syntax:"ecmascript",jsx:!0,decorators:!0,decoratorsBeforeExport:!1};case"ts":return{syntax:"typescript",decorators:!0,tsx:!0,dynamicImport:!0}}}swcJsc(e){let{target:t,polyfill:s}=this.store.empConfig.build,{externalHelpers:i}=s;return{parser:this.swcParser(e),transform:{},target:t,externalHelpers:i,preserveAllComments:!0}}get swcCoreVersion(){let[e,t]=this.coreJs.version.split(".");return`${e}.${t}`}swcOptions(e){let t={jsc:eu(this.swcJsc(e),{...this.store.empConfig.build.swcConfig}),isModule:"unknown"};return this.isPolyfill&&(delete t.jsc.target,t.env={coreJs:this.swcCoreVersion,targets:this.store.empConfig.build.polyfill.browserslist},this.store.empConfig.isESM||(t.env.mode=this.store.empConfig.build.polyfill.mode),"usage"===this.store.empConfig.build.polyfill.mode&&(t.env.shippedProposals=!0,t.env.include=this.store.empConfig.build.polyfill.include)),t}swcInitOptions(){let{externalHelpers:e}=this.store.empConfig.build.polyfill;e&&this.store.chain.resolve.alias.set("@swc/helpers",a.dirname(t.resolve("@swc/helpers/package.json"))),this.coreJs.path=t.resolve("core-js/package.json");let s=ec(this.coreJs.path);s&&(this.coreJs.version=s),this.coreJs.alias=a.dirname(this.coreJs.path),this.store.empConfig.build.polyfill.mode&&(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")}jsDataUrl(){this.store.chain.module.rule("jsDataUrl").merge({mimetype:{or:["text/javascript","application/javascript"]}}).resolve.set("fullySpecified",!1).end().use("swcJsParser").loader("builtin:swc-loader").options(this.swcJsOptions)}async scripts(){let e=[],{rule:t,use:s}=this.store.chainName;this.store.chain.merge({module:{parser:{javascript:{exportsPresence:"error",importExportsPresence:"error"}},rule:{[t.mjs]:{test:/\.m?js/,resolve:{fullySpecified:!1}},[t.typescript]:{test:/\.(ts|tsx)$/,exclude:e,use:{[s.swc]:{loader:"builtin:swc-loader",options:this.swcTsOptions}}},[t.javascript]:{test:/\.((m|c)?js|jsx)$/,exclude:e,use:{[s.swc]:{loader:"builtin:swc-loader",options:this.swcJsOptions}}}}}})}async files(){let{rule:e}=this.store.chainName;this.store.chain.merge({module:{rule:{[e.svg]:{test:/\.svg$/,type:"asset/resource"}}}}),this.store.chain.merge({module:{rule:{[e.inline]:{resourceQuery:/inline/,type:"asset/inline"}}}}),this.store.chain.merge({module:{rule:{[e.raw]:{resourceQuery:/raw/,type:"asset/source"}}}}),this.store.chain.merge({module:{rule:{[e.image]:{test:/\.(png|jpe?g|gif|webp|ico)$/i,type:"asset/resource"},[e.font]:{test:/\.(|otf|ttf|eot|woff|woff2)$/i,type:"asset/resource"},[e.svga]:{test:/\.(svga)$/i,type:"asset/resource"}}}})}},eE=new class{store;async setup(e){this.store=e;let t=[this.define(),this.anylayze(),this.progress(),this.copy(),this.minify(),this.redoctor(),this.sourceMapDevToolPlugin(),this.tsCheckerRspackPlugin(),this.cssChunkingPlugin(),this.esmLibraryPlugin()];this.beforeLifeCycle(),await this.store.empConfig.lifeCycle.beforePlugin(),await Promise.all(t),await this.store.empConfig.lifeCycle.afterPlugin()}beforeLifeCycle(){let{store:e}=this;"entry"===e.empConfig.build.polyfill.mode&&e.chain.plugin("empPolyfill").use(ek)}async anylayze(){if(!this.store.cliOptions.analyze)return;let{default:{BundleAnalyzerPlugin:e}}=await import("webpack-bundle-analyzer");this.store.chain.plugin(this.store.chainName.plugin.bundleAnalyzer).use(e,[{analyzerPort:this.store.empConfig.server.port,defaultSizes:"gzip",analyzerHost:this.store.getLanIp()||"127.0.0.1"}])}tsCheckerRspackPlugin(){if(!1===this.store.empConfig.tsCheckerRspackPlugin)return!1;this.store.chain.plugin(this.store.chainName.plugin.tsCheckerRspackPlugin).use(O,[this.store.empConfig.tsCheckerRspackPlugin])}async define(){this.store.chain.plugin(this.store.chainName.plugin.define).use(s.DefinePlugin,[this.store.empConfig.define])}async copy(){let e=this.store.resolve("public");w.existsSync(e)&&w.readdirSync(e).length>0&&this.store.chain.plugin(this.store.chainName.plugin.copy).use(s.CopyRspackPlugin,[{patterns:[{from:e,to:this.store.resolve(this.store.empConfig.build.outDir),noErrorOnMissing:!0,globOptions:{ignore:["**/.DS_Store"]}}]}])}async progress(){if("development"===this.store.mode)return;let e={};this.store.isOldRspack||(e={template:"{bar:25.green/white}{spinner:.green}{percent}% {wide_msg:.dim}",tick:void 0,progressChars:"▩▩"}),this.store.chain.plugin(this.store.chainName.plugin.progress).use(s.ProgressPlugin,[e])}minify(){this.store.chain.optimization.minimizer(this.store.chainName.minimizer.minJs).use(s.SwcJsMinimizerRspackPlugin,[this.store.empConfig.build.minOptions]);let{SwcCssMinimizerRspackPlugin:e,LightningCssMinimizerRspackPlugin:t}=s;e?this.store.chain.optimization.minimizer(this.store.chainName.minimizer.minCss).use(e,[this.store.empConfig.build.cssminOptions]):t&&this.store.chain.optimization.minimizer(this.store.chainName.minimizer.minCss).use(t,[this.store.empConfig.build.cssminOptions])}redoctor(){if(!this.store.empConfig.debug.rsdoctor)return;let{RsdoctorRspackPlugin:e}=D("@rsdoctor/rspack-plugin"),t={};"object"==typeof this.store.empConfig.debug.rsdoctor&&(t=this.store.empConfig.debug.rsdoctor),this.store.chain.plugin(this.store.chainName.plugin.rsdoctor).use(e,[t])}sourceMapDevToolPlugin(){"object"==typeof this.store.empConfig.build.sourcemap&&this.store.empConfig.build.sourcemap?.devToolPluginOptions&&this.store.chain.plugin(this.store.chainName.plugin.sourceMapDevTool).use(s.SourceMapDevToolPlugin,[this.store.empConfig.build.sourcemap.devToolPluginOptions])}circularDependency(){this.store.chain.plugin("circularDependency").use(s.CircularDependencyRspackPlugin,[{}])}cssChunkingPlugin(){this.store.empConfig.debug.cssChunkingPlugin&&this.store.chain.plugin("CssChunkingPlugin").use(s.experiments.CssChunkingPlugin,[{}])}esmLibraryPlugin(){if(!this.store.empConfig.isESM)return;let{EsmLibraryPlugin:e}=s.experiments;if(!e)return;let t=u.resolve(this.store.root,"src");this.store.chain.plugin("esmLibraryPlugin").use(e,[{preserveModules:t}]),this.store.chain.optimization.merge({runtimeChunk:!0})}},eS=new class{store;async setup(e){this.store=e;let t=[eO.setup(this.store),e$.setup(this.store),eE.setup(this.store),ex.setup(this.store),eP.setup(this.store)];await Promise.all(t),await this.store.empConfig.lifeCycle.beforeEmpPlugin(),await this.store.empConfig.plugins(),await this.store.empConfig.lifeCycle.afterEmpPlugin(),await this.store.empConfig.chain()}},eN=(e,t)=>new Promise((s,i)=>{let o=P.createServer();o.unref(),o.on("error",i),o.listen(e,t,()=>{let{port:e}=o.address();o.close(()=>{s(e)})})}),eD=async(e,t)=>{let s=new Set(["EADDRNOTAVAIL","EINVAL"]);for(let i of t)try{await eN(e,i)}catch(e){if(!s.has(e.code))throw e}return e};async function eA(e,t){let s;if(443!==e&&(e<1024||e>65535))throw Error("Port number must lie between 1024 and 65535");let i=e,o=(()=>{let e=k.networkInterfaces(),t=new Set([void 0,"0.0.0.0"]);for(let s of Object.values(e))if(s)for(let e of s)t.add(e.address);return t})();s=t&&!o.has(t)?new Set([t]):o;let r=new Set(["EADDRINUSE","EACCES"]);for(;i<=65535;)try{return await eD(i,s)}catch(e){if(!r.has(e.code))throw e;i+=1}throw Error("No available ports found")}class eR{imf={protocol:"",port:8e3,pathname:"/"};host="0.0.0.0";urls={lanUrlForConfig:"",lanUrlForTerminal:et("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 e,{host:t}=this;if("0.0.0.0"===t||"::"===t){e="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(e){}}else e=t,this.urls.lanUrlForConfig=t,this.urls.lanUrlForTerminal=this.prettyPrintUrl(this.urls.lanUrlForConfig);this.urls.localUrlForTerminal=this.prettyPrintUrl(e),this.urls.localUrlForBrowser=this.formatUrl(e)}getLanIp=eh;formatUrl(e){let{protocol:t,port:s,pathname:i}=this.imf;return j.format({protocol:t,hostname:e,port:s,pathname:i})}prettyPrintUrl(e){let{protocol:t,port:s,pathname:i}=this.imf;return j.format({protocol:t,hostname:e,port:I.bold(s),pathname:i})}}let eL=new eR,eT=h(x),e_=["Google Chrome Canary","Google Chrome Dev","Google Chrome Beta","Google Chrome","Microsoft Edge","Brave Browser","Vivaldi","Chromium"],eM=async()=>{let e=process.env.BROWSER;if(!e||!e_.includes(e)){let{stdout:t}=await eT("ps cax");e=e_.find(e=>t.includes(e))}return e},eU=async e=>{if("darwin"===process.platform)try{let t=await eM();if(t){let s=`osascript openChrome.applescript "${encodeURI(e)}" "${t}"`;return await eT(s,{cwd:eI.resource.dir}),!0}}catch(e){eo.debug(e)}try{let{default:t}=await import("open");return await t(e),!0}catch(e){return eo.error("Failed to open start URL."),eo.error(e),!1}};class eF{ip=eh();host=this.ip;isAutoDevBase=!1;isHttps=!1;httpsType="default";protocol="http";port=8e3;store;publicPath="/";publicHasHttp=!1;isOpenBrower=!1;url="";urls={localUrlForBrowser:"",localUrlForTerminal:"",lanUrlForTerminal:"",lanUrlForConfig:""};constructor(e){this.store=e}async setupOnEmpOptionSync(){"build"!==this.store.cliAction&&(this.port=await eA(this.port),this.setHttps(),await this.setAutoDevBase())}get config(){return{}}async setupOnStore(){if("build"===this.store.cliAction)return;let{store:e}=this;this.publicPath=e.rsConfig.output?.publicPath==="auto"?"/":e.rsConfig.output?.publicPath||"/",this.isOpenBrower=!!e.empConfig.server.open,this.protocol=this.isHttps?"https":"http",this.host=e.empConfig.server.host?e.empConfig.server.host:this.ip,e.empConfig.server.port&&e.empConfig.server.port!==this.port&&(this.port=await eA(e.empConfig.server.port)),eL.setup(this),this.publicPath&&(this.publicPath.indexOf("http://")>-1||this.publicPath.indexOf("https://")>-1)?(this.url=this.publicPath,this.publicHasHttp=!0,this.urls.localUrlForTerminal=eL.prettyPrintUrl("localhost")):(this.urls=eL.urls,this.url=this.urls.localUrlForBrowser)}startOpen(){let{urls:e}=this;this.publicHasHttp?(eo.info(`${z("➜")} Local: ${eo.link(e.localUrlForTerminal)}`),eo.info(`${z("➜")} Network: ${eo.link(this.publicPath)}`)):(eo.info(`${z("➜")} Local: ${eo.link(e.localUrlForTerminal)}`),eo.info(`${z("➜")} Network: ${eo.link(e.lanUrlForTerminal)}
|
|
10
|
-
`)),this.isOpenBrower&&eU(this.url)}async getcert(){let{store:e}=this,t=this.store.rsConfig.devServer||{server:{type:"http"}};if("object"==typeof t.server&&"https"===t.server.type&&t.server.options&&t.server.options.key&&t.server.options.cert)return t.server.options;let[s,i]=await Promise.all([n.readFile(e.resource.key),n.readFile(e.resource.cert)]);return{key:s,cert:i}}setHttps(){let{store:e}=this,{server:t,https:s}=e.empOptions.server||{};this.isHttps="https"===t||"object"==typeof t&&"https"===t.type||!0===s}async setAutoDevBase(){let{store:e}=this;if(this.isAutoDevBase=!!e.empOptions.autoDevBase&&"development"===e.mode&&!this.isHttpBase,!this.isAutoDevBase)return;this.protocol=this.isHttps?"https":"http",e.empOptions.server?.port&&(this.port=e.empOptions.server.port),this.port=await eA(this.port);let t=`${this.isHttps?"wss":"ws"}://${this.host}:${this.port}/ws`;e.empOptions.base=`${this.protocol}://${this.host}:${this.port}/`,e.empOptions.server=e.deepAssign({port:this.port,client:{webSocketURL:t}},e.empOptions.server)}get isHttpBase(){let e=this.store.empOptions.base||"";return e.indexOf("http://")>-1||e.indexOf("https://")>-1}}class eJ{rspack=i;rspackVersion=i.rspackVersion;isOldRspack=-1===ef(this.rspackVersion,"1.0.0");empPkg={dependencies:{},devDependencies:{},version:"2.0.0",name:""};pkg={dependencies:{},devDependencies:{},version:"0.0.0",name:""};root=process.cwd();empRoot=F;empSource=a.resolve(this.empRoot,"dist");resolve=e=>a.isAbsolute(e)?e:a.resolve(this.root,e);empResolve=e=>a.resolve(this.empRoot,e);appSrc="";outDir="";publicDir="";resource={dir:"",key:"",cert:""};chainName=
|
|
9
|
+
`)}}let eo=new ei;var er=$(import.meta.url);let en=["emp-config.ts","emp-config.js","emp.config.ts","emp.config.js","emp-config.mjs","emp-config.cjs","emp-config.mts","emp-config.cts","emp.config.mjs","emp.config.cjs","emp.config.mts","emp.config.cts"],ea=m(er,{interopDefault:!0,fsCache:!0,moduleCache:!0,cacheVersion:T.rE}),el=async()=>{let e="store.getEmpConfigPath";eo.time(e);let t=en.map(e=>u.resolve(ez.root,e)),s=await Promise.all(t.map(e=>c.promises.access(e).then(()=>!0,()=>!1))),i=t.find((e,t)=>s[t]);return eo.timeEnd(e),i},ep=async()=>{let e=u.join(ez.root,"tsconfig.json");return await c.promises.access(e).then(()=>!0,()=>!1)||(e=void 0),e},eh=()=>{let e="127.0.0.1";try{let{int:t}=f();return d(t||"")||e}catch(t){return e}},ec=e=>{try{let{version:t}=v.readJSONSync(e);return t}catch(e){return}};function em(){process.stdout.write("win32"===process.platform?"\x1b[2J\x1b[0f":"\x1b[2J\x1b[3J\x1b[H")}function eu(e,...t){for(let s of t)for(let t in s){let i=s[t],o=e[t];if(Object(i)==i&&Object(o)===o){e[t]=eu(o,i);continue}e[t]=s[t]}return e}let eg=e=>Array.isArray(e)?e:[e],ed=(e={},t=[])=>Object.keys(e).filter(e=>!t.includes(e)).reduce((t,s)=>(t[s]=e[s],t),{}),ef=(e="",t="")=>{let s=e.replace("^","").split("."),i=t.replace("^","").split("."),o=Math.max(s.length,i.length),r=0;for(let e=0;e<o;e++){let t=s.length>e?s[e]:0,o=isNaN(Number(t))?t.charCodeAt():Number(t),n=i.length>e?i[e]:0,a=isNaN(Number(n))?n.charCodeAt():Number(n);if(o<a){r=-1;break}if(o>a){r=1;break}}return r},ev=e=>{let t;if((e/=1e3)<1)return`${1e3*e} ms`;if(e<10){let t,s=e>=.01?2:3;return`${t=e.toFixed(s),z.bold(t)} s`}if(e<60){let t;return`${t=e.toFixed(1),z.bold(t)} s`}let s=e/60;return`${t=s.toFixed(2),z.bold(t)} m`},ey=e=>`data:text/javascript,${e}`,eC={rule:{mjs:"mjs",typescript:"typescript",javascript:"javascript",sourceMap:"sourceMapLoader",inline:"inline",raw:"raw",svg:"svg",image:"image",font:"fonts",svga:"svga",sass:"sass",less:"less",css:"css"},use:{swc:"swc",sourceMap:"sourceMapLoader",sass:"sassLoader",less:"lessLoader"},plugin:{tsCheckerRspackPlugin:"TsCheckerRspackPlugin",bundleAnalyzer:"bundleAnalyzerPlugin",define:"definePlugin",copy:"copyRspackPlugin",progress:"progressPlugin",html:{prefix:"html-plugin-"},rsdoctor:"rsdoctor",sourceMapDevTool:"sourceMapDevTool"},minimizer:{minJs:"minJs",minCss:"minCss"}};class eb{op={};constructor(e={}){this.op=e}async afterGetEmpOptions(){this.op.afterGetEmpOptions&&await this.op.afterGetEmpOptions()}async beforePlugin(){this.op.beforePlugin&&await this.op.beforePlugin()}async afterPlugin(){this.op.afterPlugin&&await this.op.afterPlugin()}async beforeModule(){this.op.beforeModule&&await this.op.beforeModule()}async afterModule(){this.op.afterModule&&await this.op.afterModule()}async beforeEmpPlugin(){this.op.beforeEmpPlugin&&await this.op.beforeEmpPlugin()}async afterEmpPlugin(){this.op.afterEmpPlugin&&await this.op.afterEmpPlugin()}async beforeBuild(){this.op.beforeBuild&&await this.op.beforeBuild()}async afterBulid(){this.op.afterBulid&&await this.op.afterBulid()}async beforeDevServe(){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()}}let ew=new class{store;appSrc="src";appEntry="";base="";target=[];assign(e,t){return eu(e,t=t||{})}get isESM(){return 1!==["es3","es5"].indexOf(this.store.empConfig.build.target)&&this.store.empConfig.build.useESM}lifeCycle;async setup(e){this.store=e,await this.syncEmpOptions(),await this.setupEmpOptions(),this.lifeCycle=new eb(this.store.empOptions.lifeCycle),await this.lifeCycle.afterGetEmpOptions(),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:i}=this.store.empOptions;t&&(this.appSrc=t),s&&(this.base=s),i&&(this.appEntry=i)}async setupEmpOptions(){await this.store.server.setupOnEmpOptionSync()}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(){let e=!1;return this.store.cliOptions.doctor&&(e={}),this.assign({loggerLevel:"info",clearLog:!0,progress:!0,showRsconfig:!1,showPerformance:!1,rsdoctor:e,infrastructureLogging:{appendOnly:!0,level:"warn"},newTreeshaking:this.store.empConfig.isESM,devShowAllLog:!1,showScriptDebug:!1,cssChunkingPlugin:!0,nativeWatcher:!0,warnRuleAsWarning:!0},this.store.empOptions.debug)}get build(){let e=this.store.empOptions.build?.staticDir?`${this.store.empOptions.build?.staticDir}/`:"",t={js:this.store.isDev?"cheap-module-source-map":"source-map",css:!1};return this.store.empOptions.build?.sourcemap===!0&&(t.css=!0,t.js=this.store.isDev?"cheap-module-source-map":"source-map"),this.store.empOptions.build?.devtool&&(t.js=this.store.empOptions.build?.devtool),this.assign({outDir:"dist",staticDir:e,assetsDir:"assets",publicDir:"public",chunkIds:this.store.isDev?"named":"deterministic",moduleIds:this.store.isDev?"named":"deterministic",sourcemap:t,minify:!this.store.isDev,minOptions:{},cssminOptions:{},incremental:"advance-silent",lazyCompilation:this.store.isDev,target:"es5",useESM:!1,polyfill:{mode:void 0,entryCdn:void 0,splitChunks:!1,include:[],coreJsFeatures:"stable",externalHelpers:!1,browserslist:this.store.browserslistOptions.default},swcConfig:{},devtool:this.store.isDev?"cheap-module-source-map":"source-map"},{...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:{name:"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,cache:!1!==this.cache,tags:[]},this.store.empOptions.html)}get entries(){return this.store.empOptions.entries?this.store.empOptions.entries:{}}get server(){let e={host:"0.0.0.0",port:8e3,open:"darwin"===process.platform,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"}};this.store.empOptions.server?.http2&&(this.store.server.httpsType="h2",delete this.store.empOptions.server.http2);let t=this.assign(e,this.store.empOptions.server),s="0.0.0.0"===t.host||"::"===t.host,{server:i}=this.store;if(this.store.isDev&&s&&i?.ip){let e=t.client??={};if(!e.webSocketURL){let s=i.isHttps?"wss":"ws",o=t.port??i.port??8e3;e.webSocketURL=`${s}://${i.ip}:${o}/ws`}}return t}get css(){return this.assign({sass:{mode:"modern",warnRuleAsWarning:this.store.empConfig.debug.warnRuleAsWarning},less:{lessOptions:{javascriptEnabled:!0,math:"always"}},prifixName:""},this.store.empOptions.css)}get output(){let e=(this.store.isDev,".[contenthash:8]"),t=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]${e}.js`,cssFilename:`${i}css/[name]${t}.css`,cssChunkFilename:`${i}css/[name]${t}.css`,assetModuleFilename:`${i}${s}/[name]${e}[ext][query]`,path:this.store.outDir,clean:!this.store.isDev,uniqueName:this.store.uniqueName};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)}get tsCheckerRspackPlugin(){let e={};return!!this.store.empOptions.tsCheckerRspackPlugin&&("object"==typeof this.store.empOptions.tsCheckerRspackPlugin&&(e=this.store.empOptions.tsCheckerRspackPlugin),this.assign({},e))}setDefine(e){let t=this.store.empOptions.defineFix?this.store.empOptions.defineFix:this.isESM?"esm":"cjs",s={};return Object.keys(e).map(i=>{"all"===t?(s[`import.meta.env.${i}`]=JSON.stringify(e[i]),s[`process.env.${i}`]=JSON.stringify(e[i])):"esm"===t?s[`import.meta.env.${i}`]=JSON.stringify(e[i]):"cjs"===t?s[`process.env.${i}`]=JSON.stringify(e[i]):"none"===t&&(s[`${i}`]=JSON.stringify(e[i]))}),s}get externals(){return this.assign({},this.store.empOptions.externals)}get resolve(){return eu({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="store.jiti.loadConfig.empConfig";if(eo.time(e),!this.store.rootPaths.empConfig)return;let{default:t}=await ea(this.store.rootPaths.empConfig);"function"==typeof t?this.store.empOptions=await t(this.store):this.store.empOptions=t||{},eo.timeEnd(e)}get moduleTransformRule(){let{moduleTransform:e}=this.store.empOptions,t=this.assign({defaultExclude:!1},e),s={and:[],not:[]};return!0===t.defaultExclude&&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 cache(){return!1!==this.store.empOptions.cache&&(this.store.empOptions.cache?this.store.empOptions.cache:"persistent")}get ignoreWarnings(){return this.store.empOptions.ignoreWarnings?this.store.empOptions.ignoreWarnings:[/Conflicting order/]}get autoPages(){let e;return this.store.empOptions.autoPages&&(e="boolean"==typeof this.store.empOptions.autoPages?{}:this.store.empOptions.autoPages,e=this.assign({path:"pages"},e)),e}showLogTitle(e){this.store.empOptions.showLogTitle?this.store.empOptions.showLogTitle(e):eo.title(`${e.cliAction}`)}},eO=new class{store;async setup(e){this.store=e;let t=[this.common(),this.stats(),this.devServer(),this.optimization(),this.checkTsconfig()];await Promise.all(t)}get cache(){let e;if(!1===this.store.empConfig.cache)return!1;let t={type:"persistent"===this.store.empConfig.cache?"persistent":"memory",buildDependencies:(e=[er],ez.rootPaths.pkg&&e.push(ez.rootPaths.pkg),ez.rootPaths.empConfig&&e.push(ez.rootPaths.empConfig),ez.rootPaths.tsConfig&&e.push(ez.rootPaths.tsConfig),e),version:this.store.empConfig.server.port?`${this.store.empPkg.version}_${this.store.empConfig.server.port}`:this.store.empPkg.version};return"object"==typeof this.store.empConfig.cache&&(t=this.store.deepAssign(t,this.store.empConfig.cache)),t}get name(){let e=this.store.empConfig.server.port?`_${this.store.empConfig.server.port}`:"";return this.store.pkg.name+e}async common(){this.store.merge({name:this.name,node:{global:!0},experiments:{nativeWatcher:this.store.empConfig.debug.nativeWatcher,asyncWebAssembly:!0},incremental:this.store.empConfig.build.incremental,lazyCompilation:this.store.empConfig.build.lazyCompilation,target:this.store.empConfig.target,infrastructureLogging:this.store.empConfig.debug.infrastructureLogging,context:this.store.root,mode:this.store.mode,cache:this.cache,devtool:this.store.empConfig.build.sourcemap.js,output:{...this.store.empConfig.output,bundlerInfo:{force:!1},module:this.store.empConfig.output.module||this.store.empConfig.isESM},resolve:this.store.empConfig.resolve,externals:this.store.empConfig.externals,ignoreWarnings:this.store.empConfig.ignoreWarnings,watchOptions:{ignored:["**/node_modules/**","**/@mf-types/**"]}})}async checkTsconfig(){let e=this.store.resolve("tsconfig.json");if(await v.exists(e)){let t={};this.store.isOldRspack?t.tsConfigPath=e:t.tsConfig=e,this.store.merge({resolve:t})}}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:{}}};"entry"===this.store.empConfig.build.polyfill.mode&&this.store.empConfig.build.polyfill.splitChunks&&!this.store.empConfig.build.polyfill.entryCdn&&(e.splitChunks.cacheGroups.coreJs={test:/[\\/]node_modules[\\/](core-js)[\\/]/,name:"coreJs",chunks:"all",enforce:!0}),this.store.chain.merge({optimization:e})}},eP=new class{store;async setup(e){this.store=e;let t=[this.sass(),this.less(),this.css()];await Promise.all(t)}async sass(){let{rule:e,use:s}=this.store.chainName,i={},{sass:o}=this.store.empConfig.css;"modern"===o.mode&&(i.implementation=o.implementation?o.implementation:t.resolve("sass-embedded"),i.api="modern-compiler",i.sourceMap=this.store.empConfig.build.sourcemap.css,o.sassOptions&&(i.sassOptions=o.sassOptions)),void 0!==o.additionalData&&(i.additionalData=o.additionalData),void 0!==o.warnRuleAsWarning&&(i.warnRuleAsWarning=o.warnRuleAsWarning),void 0!==o.webpackImporter&&(i.webpackImporter=o.webpackImporter),this.store.chain.merge({module:{rule:{[e.sass]:{test:/\.(sass|scss)$/,use:{[s.sass]:{loader:t.resolve("sass-loader"),options:i}},type:"css/auto"}}}})}async less(){let{rule:e,use:s}=this.store.chainName,{lessOptions:i}=this.store.empConfig.css.less,o={loader:t.resolve("less-loader"),options:{lessOptions:i}};this.store.chain.merge({module:{rule:{[e.less]:{test:/\.less$/,use:{[s.less]:o},type:"css/auto"}}}})}async css(){let{rule:e}=this.store.chainName;this.store.chain.merge({module:{rule:{[e.css]:{test:/\.css$/,use:{},type:"css/auto"}}}})}};class ek{apply(e){let{webpack:t}=e;ez.empConfig.build.polyfill.entryCdn||new t.EntryPlugin(e.context,ey(`import 'core-js/${ez.empConfig.build.polyfill.coreJsFeatures}'`),{name:void 0}).apply(e)}}class ej{PluginName="HtmlEmpInjectPlugin";chunk="";files=[];constructor(e,t="",s=""){this.PluginName=`${this.PluginName}-${t}`,this.files=e,this.chunk=s}apply(e){e.hooks.compilation.tap(this.PluginName,e=>{b.getHooks(e).alterAssetTagGroups.tapPromise(this.PluginName,async e=>(this.chunk&&!e.plugin.userOptions.chunks?.includes(this.chunk)||this.files.map(t=>{let{pos:s,...i}=t;("body"===s?e.bodyTags:e.headTags).push({attributes:{},voidTag:!1,meta:{plugin:void 0},tagName:"script",...i})}),e))})}}let ex=new 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),this.prepareAndSetAsset(e),e}prepareAndSetAsset(e){let t=e.chunks?e.chunks[0]:void 0;this.store.injectTags(e.tags,t?`injectTags-${t}`:"injectTags",t),delete e.tags}injectPolyfill(){if(!this.store.empConfig.build.polyfill.entryCdn)return;let e=[{attributes:{src:this.store.empConfig.build.polyfill.entryCdn},tagName:"script",pos:"head"}];this.store.injectTags(e,"injectEMPPolyfill")}setChunk(e){return e.replace(a.extname(e),"").replace(`${this.store.empConfig.appSrc}${a.sep}`,"")}setTemplate(e){return e?this.store.resolve(e):this.store.empResolve(a.join("template","index.html"))}setFavicion(e){if(""!==e)return e?this.store.resolve(e):this.store.empResolve(a.join("template","favicon.ico"))}setEntryItem(e,t,s){s=s||this.store.resolve(a.join(this.store.empConfig.appSrc,e));let i=this.setChunk(e),o=[s];this.entriesConfig[i]={entry:{[i]:o},html:this.setHtmlConfig(t,[i])},this.store.entries[i]=o}setRspackHtmlPlugin(e,t){this.store.chain.plugin(`${this.store.chainName.plugin.html.prefix}${t}`).use(b,[e])}setRspackEntry(e){this.store.merge({entry:e})}async init(){this.injectPolyfill(),this.store.empConfig.autoPages?await this.setAutoPage():(await this.setDefaultEntry(),this.setEntryByConfig())}async setAutoPage(){eo.time("setAutoPage");let e=this.store.empConfig.autoPages?.path||"pages",t=a.join(this.store.appSrc,e),s=a.join(t,"**","*.{ts,tsx,jsx,js}"),i=await C([s],{windowsPathsNoEscape:!0});(i=i.map(e=>e.replace(`${t}${a.sep}`,""))).map(e=>{let s=this.store.empConfig.entries[e]||{};this.setEntryItem(e,{...this.store.empConfig.html,...s},a.join(t,e))}),eo.timeEnd("setAutoPage")}async setDefaultEntry(){let e="store.empConfig.setDefaultEntry";eo.time(e);let t=a.join(this.store.appSrc,this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index.{ts,tsx,jsx,js}"),s=await C([t],{windowsPathsNoEscape:!0});if(s[0]){let e=a.join(this.store.empConfig.appSrc,Object.keys(this.store.empConfig.entries).length>0&&this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index");this.setEntryItem(e,this.store.empConfig.html,s[0])}eo.timeEnd(e)}setEntryByConfig(){if(Object.keys(this.store.empConfig.entries).length>0)for(let[e,t]of Object.entries(this.store.empConfig.entries))this.setEntryItem(e,{...this.store.empConfig.html,...t})}toConfig(){for(let[e,t]of Object.entries(this.entriesConfig))this.setRspackHtmlPlugin(t.html,e),this.setRspackEntry(t.entry)}},e$=new class{store;swcJsOptions={};swcTsOptions={};coreJs={version:"3",alias:"",path:""};async setup(e){this.store=e,this.swcInitOptions(),await this.run()}async run(){let e=[this.jsDataUrl(),this.files(),this.scripts(),this.rspackGenerator(),this.rspackParser()];await this.store.empConfig.lifeCycle.beforeModule(),await Promise.all(e),await this.store.empConfig.lifeCycle.afterModule()}rspackGenerator(){let e=this.store.empConfig.css?.prifixName?`${this.store.empConfig.css?.prifixName}-`:"",t=this.store.isDev?`${e}[id]-[local]-[hash:base64:8]`:`${e}[local]-[hash:5]`;this.store.chain.merge({module:{generator:{"css/auto":{exportsConvention:"as-is",exportsOnly:!1,localIdentName:t,esModule:!0},css:{exportsOnly:!1,esModule:!0},"css/module":{exportsConvention:"as-is",exportsOnly:!1,localIdentName:t,esModule:!0},json:{JSONParse:!0}}}})}rspackParser(){this.store.chain.merge({module:{parser:{javascript:{dynamicImportMode:"lazy",dynamicImportPrefetch:!1,dynamicImportPreload:!1,url:!0,importMeta:!0},css:{namedExports:!1},"css/auto":{namedExports:!1},"css/module":{namedExports:!1}}}})}get isPolyfill(){return!!this.store.empConfig.build.polyfill.mode}swcParser(e){switch(e){case"js":return{syntax:"ecmascript",jsx:!0,decorators:!0,decoratorsBeforeExport:!1};case"ts":return{syntax:"typescript",decorators:!0,tsx:!0,dynamicImport:!0}}}swcJsc(e){let{target:t,polyfill:s}=this.store.empConfig.build,{externalHelpers:i}=s;return{parser:this.swcParser(e),transform:{},target:t,externalHelpers:i,preserveAllComments:!0}}get swcCoreVersion(){let[e,t]=this.coreJs.version.split(".");return`${e}.${t}`}swcOptions(e){let t={jsc:eu(this.swcJsc(e),{...this.store.empConfig.build.swcConfig}),isModule:"unknown"};return this.isPolyfill&&(delete t.jsc.target,t.env={coreJs:this.swcCoreVersion,targets:this.store.empConfig.build.polyfill.browserslist},this.store.empConfig.isESM||(t.env.mode=this.store.empConfig.build.polyfill.mode),"usage"===this.store.empConfig.build.polyfill.mode&&(t.env.shippedProposals=!0,t.env.include=this.store.empConfig.build.polyfill.include)),t}swcInitOptions(){let{externalHelpers:e}=this.store.empConfig.build.polyfill;e&&this.store.chain.resolve.alias.set("@swc/helpers",a.dirname(t.resolve("@swc/helpers/package.json"))),this.coreJs.path=t.resolve("core-js/package.json");let s=ec(this.coreJs.path);s&&(this.coreJs.version=s),this.coreJs.alias=a.dirname(this.coreJs.path),this.store.empConfig.build.polyfill.mode&&(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")}jsDataUrl(){this.store.chain.module.rule("jsDataUrl").merge({mimetype:{or:["text/javascript","application/javascript"]}}).resolve.set("fullySpecified",!1).end().use("swcJsParser").loader("builtin:swc-loader").options(this.swcJsOptions)}async scripts(){let e=[],{rule:t,use:s}=this.store.chainName;this.store.chain.merge({module:{parser:{javascript:{exportsPresence:"error",importExportsPresence:"error"}},rule:{[t.mjs]:{test:/\.m?js/,resolve:{fullySpecified:!1}},[t.typescript]:{test:/\.(ts|tsx)$/,exclude:e,use:{[s.swc]:{loader:"builtin:swc-loader",options:this.swcTsOptions}}},[t.javascript]:{test:/\.((m|c)?js|jsx)$/,exclude:e,use:{[s.swc]:{loader:"builtin:swc-loader",options:this.swcJsOptions}}}}}})}async files(){let{rule:e}=this.store.chainName;this.store.chain.merge({module:{rule:{[e.svg]:{test:/\.svg$/,type:"asset/resource"}}}}),this.store.chain.merge({module:{rule:{[e.inline]:{resourceQuery:/inline/,type:"asset/inline"}}}}),this.store.chain.merge({module:{rule:{[e.raw]:{resourceQuery:/raw/,type:"asset/source"}}}}),this.store.chain.merge({module:{rule:{[e.image]:{test:/\.(png|jpe?g|gif|webp|ico)$/i,type:"asset/resource"},[e.font]:{test:/\.(|otf|ttf|eot|woff|woff2)$/i,type:"asset/resource"},[e.svga]:{test:/\.(svga)$/i,type:"asset/resource"}}}})}},eE=new class{store;async setup(e){this.store=e;let t=[this.define(),this.anylayze(),this.progress(),this.copy(),this.minify(),this.redoctor(),this.sourceMapDevToolPlugin(),this.tsCheckerRspackPlugin(),this.cssChunkingPlugin(),this.esmLibraryPlugin()];this.beforeLifeCycle(),await this.store.empConfig.lifeCycle.beforePlugin(),await Promise.all(t),await this.store.empConfig.lifeCycle.afterPlugin()}beforeLifeCycle(){let{store:e}=this;"entry"===e.empConfig.build.polyfill.mode&&e.chain.plugin("empPolyfill").use(ek)}async anylayze(){if(!this.store.cliOptions.analyze)return;let{default:{BundleAnalyzerPlugin:e}}=await import("webpack-bundle-analyzer");this.store.chain.plugin(this.store.chainName.plugin.bundleAnalyzer).use(e,[{analyzerPort:this.store.empConfig.server.port,defaultSizes:"gzip",analyzerHost:this.store.getLanIp()||"127.0.0.1"}])}tsCheckerRspackPlugin(){if(!1===this.store.empConfig.tsCheckerRspackPlugin)return!1;this.store.chain.plugin(this.store.chainName.plugin.tsCheckerRspackPlugin).use(O,[this.store.empConfig.tsCheckerRspackPlugin])}async define(){this.store.chain.plugin(this.store.chainName.plugin.define).use(s.DefinePlugin,[this.store.empConfig.define])}async copy(){let e=this.store.resolve("public");w.existsSync(e)&&w.readdirSync(e).length>0&&this.store.chain.plugin(this.store.chainName.plugin.copy).use(s.CopyRspackPlugin,[{patterns:[{from:e,to:this.store.resolve(this.store.empConfig.build.outDir),noErrorOnMissing:!0,globOptions:{ignore:["**/.DS_Store"]}}]}])}async progress(){if("development"===this.store.mode)return;let e={};this.store.isOldRspack||(e={template:"{bar:25.green/white}{spinner:.green}{percent}% {wide_msg:.dim}",tick:void 0,progressChars:"▩▩"}),this.store.chain.plugin(this.store.chainName.plugin.progress).use(s.ProgressPlugin,[e])}minify(){this.store.chain.optimization.minimizer(this.store.chainName.minimizer.minJs).use(s.SwcJsMinimizerRspackPlugin,[this.store.empConfig.build.minOptions]);let{SwcCssMinimizerRspackPlugin:e,LightningCssMinimizerRspackPlugin:t}=s;e?this.store.chain.optimization.minimizer(this.store.chainName.minimizer.minCss).use(e,[this.store.empConfig.build.cssminOptions]):t&&this.store.chain.optimization.minimizer(this.store.chainName.minimizer.minCss).use(t,[this.store.empConfig.build.cssminOptions])}redoctor(){if(!this.store.empConfig.debug.rsdoctor)return;let{RsdoctorRspackPlugin:e}=D("@rsdoctor/rspack-plugin"),t={};"object"==typeof this.store.empConfig.debug.rsdoctor&&(t=this.store.empConfig.debug.rsdoctor),this.store.chain.plugin(this.store.chainName.plugin.rsdoctor).use(e,[t])}sourceMapDevToolPlugin(){"object"==typeof this.store.empConfig.build.sourcemap&&this.store.empConfig.build.sourcemap?.devToolPluginOptions&&this.store.chain.plugin(this.store.chainName.plugin.sourceMapDevTool).use(s.SourceMapDevToolPlugin,[this.store.empConfig.build.sourcemap.devToolPluginOptions])}circularDependency(){this.store.chain.plugin("circularDependency").use(s.CircularDependencyRspackPlugin,[{}])}cssChunkingPlugin(){let e=!0===this.store.empConfig.debug.cssChunkingPlugin?{}:this.store.empConfig.debug.cssChunkingPlugin;e&&this.store.chain.plugin("CssChunkingPlugin").use(s.experiments.CssChunkingPlugin,[e])}esmLibraryPlugin(){if(!this.store.empConfig.isESM)return;let{EsmLibraryPlugin:e}=s.experiments;if(!e)return;let t=u.resolve(this.store.root,"src");this.store.chain.plugin("esmLibraryPlugin").use(e,[{preserveModules:t}]),this.store.chain.optimization.merge({runtimeChunk:!0})}},eS=new class{store;async setup(e){this.store=e;let t=[eO.setup(this.store),e$.setup(this.store),eE.setup(this.store),ex.setup(this.store),eP.setup(this.store)];await Promise.all(t),await this.store.empConfig.lifeCycle.beforeEmpPlugin(),await this.store.empConfig.plugins(),await this.store.empConfig.lifeCycle.afterEmpPlugin(),await this.store.empConfig.chain()}},eN=(e,t)=>new Promise((s,i)=>{let o=P.createServer();o.unref(),o.on("error",i),o.listen(e,t,()=>{let{port:e}=o.address();o.close(()=>{s(e)})})}),eD=async(e,t)=>{let s=new Set(["EADDRNOTAVAIL","EINVAL"]);for(let i of t)try{await eN(e,i)}catch(e){if(!s.has(e.code))throw e}return e};async function eA(e,t){let s;if(443!==e&&(e<1024||e>65535))throw Error("Port number must lie between 1024 and 65535");let i=e,o=(()=>{let e=k.networkInterfaces(),t=new Set([void 0,"0.0.0.0"]);for(let s of Object.values(e))if(s)for(let e of s)t.add(e.address);return t})();s=t&&!o.has(t)?new Set([t]):o;let r=new Set(["EADDRINUSE","EACCES"]);for(;i<=65535;)try{return await eD(i,s)}catch(e){if(!r.has(e.code))throw e;i+=1}throw Error("No available ports found")}class eR{imf={protocol:"",port:8e3,pathname:"/"};host="0.0.0.0";urls={lanUrlForConfig:"",lanUrlForTerminal:et("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 e,{host:t}=this;if("0.0.0.0"===t||"::"===t){e="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(e){}}else e=t,this.urls.lanUrlForConfig=t,this.urls.lanUrlForTerminal=this.prettyPrintUrl(this.urls.lanUrlForConfig);this.urls.localUrlForTerminal=this.prettyPrintUrl(e),this.urls.localUrlForBrowser=this.formatUrl(e)}getLanIp=eh;formatUrl(e){let{protocol:t,port:s,pathname:i}=this.imf;return j.format({protocol:t,hostname:e,port:s,pathname:i})}prettyPrintUrl(e){let{protocol:t,port:s,pathname:i}=this.imf;return j.format({protocol:t,hostname:e,port:z.bold(s),pathname:i})}}let eL=new eR,eT=h(x),e_=["Google Chrome Canary","Google Chrome Dev","Google Chrome Beta","Google Chrome","Microsoft Edge","Brave Browser","Vivaldi","Chromium"],eM=async()=>{let e=process.env.BROWSER;if(!e||!e_.includes(e)){let{stdout:t}=await eT("ps cax");e=e_.find(e=>t.includes(e))}return e},eU=async e=>{if("darwin"===process.platform)try{let t=await eM();if(t){let s=`osascript openChrome.applescript "${encodeURI(e)}" "${t}"`;return await eT(s,{cwd:ez.resource.dir}),!0}}catch(e){eo.debug(e)}try{let{default:t}=await import("open");return await t(e),!0}catch(e){return eo.error("Failed to open start URL."),eo.error(e),!1}};class eF{ip=eh();host=this.ip;isAutoDevBase=!1;isHttps=!1;httpsType="default";protocol="http";port=8e3;store;publicPath="/";publicHasHttp=!1;isOpenBrower=!1;url="";urls={localUrlForBrowser:"",localUrlForTerminal:"",lanUrlForTerminal:"",lanUrlForConfig:""};constructor(e){this.store=e}async setupOnEmpOptionSync(){"build"!==this.store.cliAction&&(this.port=await eA(this.port),this.setHttps(),await this.setAutoDevBase())}get config(){return{}}async setupOnStore(){if("build"===this.store.cliAction)return;let{store:e}=this;this.publicPath=e.rsConfig.output?.publicPath==="auto"?"/":e.rsConfig.output?.publicPath||"/",this.isOpenBrower=!!e.empConfig.server.open,this.protocol=this.isHttps?"https":"http",this.host=e.empConfig.server.host?e.empConfig.server.host:this.ip,e.empConfig.server.port&&e.empConfig.server.port!==this.port&&(this.port=await eA(e.empConfig.server.port)),eL.setup(this),this.publicPath&&(this.publicPath.indexOf("http://")>-1||this.publicPath.indexOf("https://")>-1)?(this.url=this.publicPath,this.publicHasHttp=!0,this.urls.localUrlForTerminal=eL.prettyPrintUrl("localhost")):(this.urls=eL.urls,this.url=this.urls.localUrlForBrowser)}startOpen(){let{urls:e}=this;this.publicHasHttp?(eo.info(`${H("➜")} Local: ${eo.link(e.localUrlForTerminal)}`),eo.info(`${H("➜")} Network: ${eo.link(this.publicPath)}`)):(eo.info(`${H("➜")} Local: ${eo.link(e.localUrlForTerminal)}`),eo.info(`${H("➜")} Network: ${eo.link(e.lanUrlForTerminal)}
|
|
10
|
+
`)),this.isOpenBrower&&eU(this.url)}async getcert(){let{store:e}=this,t=this.store.rsConfig.devServer||{server:{type:"http"}};if("object"==typeof t.server&&"https"===t.server.type&&t.server.options&&t.server.options.key&&t.server.options.cert)return t.server.options;let[s,i]=await Promise.all([n.readFile(e.resource.key),n.readFile(e.resource.cert)]);return{key:s,cert:i}}setHttps(){let{store:e}=this,{server:t,https:s}=e.empOptions.server||{};this.isHttps="https"===t||"object"==typeof t&&"https"===t.type||!0===s}async setAutoDevBase(){let{store:e}=this;if(this.isAutoDevBase=!!e.empOptions.autoDevBase&&"development"===e.mode&&!this.isHttpBase,!this.isAutoDevBase)return;this.protocol=this.isHttps?"https":"http",e.empOptions.server?.port&&(this.port=e.empOptions.server.port),this.port=await eA(this.port);let t=`${this.isHttps?"wss":"ws"}://${this.host}:${this.port}/ws`;e.empOptions.base=`${this.protocol}://${this.host}:${this.port}/`,e.empOptions.server=e.deepAssign({port:this.port,client:{webSocketURL:t}},e.empOptions.server)}get isHttpBase(){let e=this.store.empOptions.base||"";return e.indexOf("http://")>-1||e.indexOf("https://")>-1}}class eJ{rspack=i;rspackVersion=i.rspackVersion;isOldRspack=-1===ef(this.rspackVersion,"1.0.0");empPkg={dependencies:{},devDependencies:{},version:"2.0.0",name:""};pkg={dependencies:{},devDependencies:{},version:"0.0.0",name:""};root=process.cwd();empRoot=F;empSource=a.resolve(this.empRoot,"dist");resolve=e=>a.isAbsolute(e)?e:a.resolve(this.root,e);empResolve=e=>a.resolve(this.empRoot,e);appSrc="";outDir="";publicDir="";resource={dir:"",key:"",cert:""};chainName=eC;server=new eF(this);cacheDir="";mode="development";cliMode="dev";isDev=!0;chain;rsConfig;empOptions={};empConfig;entries={};debug;cliAction;cliOptions;rootPaths={empConfig:void 0,tsConfig:void 0,pkg:void 0};beforeSetup;afterSetup;async setup(e,t){this.cliAction=e||this.cliAction,this.cliOptions=t||this.cliOptions;let s="store.setup";eo.time(s),this.beforeSetup&&await this.beforeSetup();let[i,o]=await Promise.all([el(),ep()]);this.rootPaths.empConfig=i,this.rootPaths.tsConfig=o,this.rootPaths.pkg=this.resolve("package.json"),await this.initVars(this.cliAction,this.cliOptions),this.empConfig=ew,await this.empConfig.setup(this),this.debug={...this.empConfig.debug},this.initPaths(),this.chain=new y,await eS.setup(this),this.setLogger(),this.toConfig(),this.logConfig(),await this.server.setupOnStore(),this.afterSetup&&await this.afterSetup(),eo.timeEnd(s),this.debug.clearLog&&em()}async initVars(e,s){this.cliAction=e,this.cliOptions=s||{},this.cliMode="prod",this.mode="dev"===e?"development":"production",this.isDev="development"===this.mode,process.env.NODE_ENV="dev"===e?"development":"production";let i=t(this.empResolve("package.json")),o=t(this.resolve("package.json"));this.empPkg={...this.empPkg,...i},this.pkg={...this.pkg,...o},this.resource.dir=a.join(this.empRoot,"resource"),this.resource.cert=a.join(this.resource.dir,"emp.cert"),this.resource.key=a.join(this.resource.dir,"emp.key")}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)}loggerExtensionName="";setLoggerExtensionName(e){this.loggerExtensionName=e}setLogger(){let e="dev"===this.cliMode?"debug":"info";this.debug.loggerLevel&&(e=this.debug.loggerLevel),eo.setup({fullName:`EMP⚡${this.empPkg.version}${"dev"===this.cliMode?".DEV":""}${this.loggerExtensionName?" "+this.loggerExtensionName:""}`,brandName:"EMP",logLevel:e})}merge(e){this.chain.merge(e)}toConfig(){this.rsConfig=this.chain.toConfig()}logConfig(){if(this.debug.showRsconfig)if("string"==typeof this.debug.showRsconfig){let e=a.join(this.root,this.debug.showRsconfig);n.writeFile(e,JSON.stringify(this.rsConfig,null,2))}else{this.debug.clearLog=!1;let e={colors:!0,depth:null},t="object"==typeof this.debug.showRsconfig?eu(e,this.debug.showRsconfig):e;console.log(eo.link("[Compile Config]")),console.log(p.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 >= 16"]}}get uniqueName(){return this.encodeVarName(this.pkg.name)}encodeVarName(e){return e.replaceAll("/","_").replaceAll("@","_").replaceAll("-","_")}vCompare=ef;deepAssign=eu;getLanIp=eh;injectTags(e=[],t="",s=""){this.chain.plugin(`${ej}-${t}`).use(ej,[e,t,s])}}let ez=new eJ;function eI(e){return e}export{A as __webpack_require__,ei as Logger,X as blue,z as chalk,es as color,eu as deepAssign,eI as defineConfig,et as gray,H as green,R as empHelper,eo as logger,ee as magenta,o as program,G as red,i as rspack,_ as runScript,ez as store,ev as timeFormat,Y as white,q as yellow};
|
package/dist/types/config.d.ts
CHANGED
|
@@ -37,7 +37,12 @@ export type DebugType = {
|
|
|
37
37
|
* https://rspack.rs/zh/plugins/rspack/css-chunking-plugin
|
|
38
38
|
* 启用 CssChunkingPlugin 后,SplitChunksPlugin 将不再处理 CSS 模块。 这意味着 optimization.splitChunks 等配置对 CSS 模块将不再生效,所有 CSS 模块的代码分割逻辑完全由 CssChunkingPlugin 处理。
|
|
39
39
|
*/
|
|
40
|
-
cssChunkingPlugin?: boolean
|
|
40
|
+
cssChunkingPlugin?: boolean | Record<string, any>;
|
|
41
|
+
/**
|
|
42
|
+
* 是否启用 Rspack 原生文件监听器。
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
nativeWatcher?: boolean;
|
|
41
46
|
};
|
|
42
47
|
export type ServerType = devServerConfig & {
|
|
43
48
|
/**
|
|
@@ -153,6 +158,16 @@ export type BuildType = {
|
|
|
153
158
|
*/
|
|
154
159
|
minOptions?: SwcJsMinimizerRspackPluginOptions;
|
|
155
160
|
cssminOptions?: CssminOptionsType;
|
|
161
|
+
/**
|
|
162
|
+
* Rspack incremental build 配置。
|
|
163
|
+
* @default 'advance-silent'
|
|
164
|
+
*/
|
|
165
|
+
incremental?: RsConfig['incremental'];
|
|
166
|
+
/**
|
|
167
|
+
* Rspack lazy compilation 配置。
|
|
168
|
+
* @default development mode true
|
|
169
|
+
*/
|
|
170
|
+
lazyCompilation?: RsConfig['lazyCompilation'];
|
|
156
171
|
/**
|
|
157
172
|
* 生成代码 参考 https://swc.rs/docs/configuring-swc#jsctarget
|
|
158
173
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empjs/cli",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.2",
|
|
4
4
|
"description": "emp",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -113,12 +113,12 @@
|
|
|
113
113
|
"less-loader": "^12.2.0",
|
|
114
114
|
"open": "10.2.0",
|
|
115
115
|
"sass-embedded": "1.93.2",
|
|
116
|
-
"sass-loader": "
|
|
116
|
+
"sass-loader": "17.0.0",
|
|
117
117
|
"serve-static": "2.2.0",
|
|
118
|
-
"ts-checker-rspack-plugin": "1.
|
|
118
|
+
"ts-checker-rspack-plugin": "1.4.0",
|
|
119
119
|
"typescript-plugin-css-modules": "5.2.0",
|
|
120
120
|
"webpack-bundle-analyzer": "4.10.2",
|
|
121
|
-
"@empjs/chain": "4.0.0-alpha.
|
|
121
|
+
"@empjs/chain": "4.0.0-alpha.2"
|
|
122
122
|
},
|
|
123
123
|
"scripts": {
|
|
124
124
|
"dev": "rslib build --watch --env-mode development",
|