xhs-mp-compiler-cli 2.1.4 → 2.1.6-beta.0

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.
@@ -25,6 +25,7 @@ export interface ICheckOptions {
25
25
  compressJs?: boolean;
26
26
  enableV2?: boolean;
27
27
  enableV1?: boolean;
28
+ entryType?: string;
28
29
  }
29
30
  export declare abstract class AbstractCompiler extends EventEmitter {
30
31
  protected inspectPort: any;
@@ -1 +1 @@
1
- var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){return new(P||(P=Promise))((function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator.throw(value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):function adopt(value){return value instanceof P?value:new P((function(resolve){resolve(value)}))}(result.value).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())}))},__importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};!function(factory){if("object"==typeof module&&"object"==typeof module.exports){var v=factory(require,exports);void 0!==v&&(module.exports=v)}else{"function"==typeof define&&define.amd&&define(["require","exports","./config/constant.config","xhs-mp-project","events","fs-extra","path","./utils/utils","./utils/project","./utils/file","./config/dir.config","./compiler","./sharedFs"],factory)}}((function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ProjectCompilerManager=exports.prepareDevPool=exports.COMPILE_ENTRY=void 0;const constant_config_1=require("./config/constant.config");Object.defineProperty(exports,"COMPILE_ENTRY",{enumerable:!0,get:function(){return constant_config_1.COMPILE_ENTRY}});const xhs_mp_project_1=require("xhs-mp-project"),events_1=__importDefault(require("events")),fs_extra_1=__importDefault(require("fs-extra")),path_1=__importDefault(require("path")),utils_1=require("./utils/utils"),project_1=require("./utils/project"),file_1=require("./utils/file"),dir_config_1=require("./config/dir.config"),compiler_1=require("./compiler");Object.defineProperty(exports,"prepareDevPool",{enumerable:!0,get:function(){return compiler_1.prepareDevPool}});const sharedFs_1=__importDefault(require("./sharedFs"));class ProjectCompilerManager extends events_1.default{constructor(props){super(),this.compilerImplMap={},this.getCompiler=(entryType=constant_config_1.COMPILE_ENTRY.simulator)=>(this.compilerImplMap[entryType]||(this.compilerImplMap[entryType]=this.createCompiler(entryType),entryType===constant_config_1.COMPILE_ENTRY.simulator?this.initSimulatorCompiler(this.compilerImplMap[entryType]):this.initBuildCompiler(this.compilerImplMap[entryType])),this.compilerImplMap[entryType]),this.initSimulatorCompiler=compiler=>{compiler.on("buildStart",(data=>{this.emit("simulator-compile-start",data)})),compiler.on("buildEnd",(data=>{this.emit("simulator-compile-end",data)})),compiler.on("compileInfo",(data=>{this.emit("simulator-compile-info",data)})),compiler.on("compilePercent",(data=>{this.emit("simulator-compile-percent",data)})),compiler.on("compileErrorWhenFileChange",(error=>{this.emit("simulator-file-change-compile-error",error)})),compiler.on("compileFinishWhenFileChange",(data=>{this.emit("simulator-file-change-compile-finish",data)})),compiler.on("uncaughtException",(err=>{this.emit("simulator-uncaught-exception",err)}))},this.initBuildCompiler=compiler=>{compiler.on("compilePercent",(data=>{this.emit("full-compile-percent",data)})),compiler.on("compileInfo",(data=>{this.emit("full-compiler-info",data)})),compiler.on("uncaughtException",(err=>{this.emit("full-compile-uncaught-exception",err)}))};const{logger:logger,report:report,projectPath:projectPath,project:project}=props;this.logger=logger||console,this.report=report,this.compilerProps=props,(project||projectPath)&&(this.project=project||new xhs_mp_project_1.Project({projectPath:projectPath}))}bindProject(props){const{projectPath:projectPath,project:project}=props;if(!project&&!projectPath){throw new Error("project 和 projectPath 均为undefined")}this.project=project||new xhs_mp_project_1.Project({projectPath:projectPath})}getCompilerType(entryType=constant_config_1.COMPILE_ENTRY.simulator){const isGame=this.project.appMode===constant_config_1.MiniMode.minigame,settings=this.project.settings||{};return isGame||!settings.useNewCompiler?entryType===constant_config_1.COMPILE_ENTRY.simulator?constant_config_1.COMPILER_TYPE.legacy_dev:constant_config_1.COMPILER_TYPE.legacy_build:entryType===constant_config_1.COMPILE_ENTRY.simulator?constant_config_1.COMPILER_TYPE.dev:entryType===constant_config_1.COMPILE_ENTRY.upload?constant_config_1.COMPILER_TYPE.legacy_build:constant_config_1.COMPILER_TYPE.build}getDistDir(entryType=constant_config_1.COMPILE_ENTRY.simulator){const{compileDistDir:compileDistDir=dir_config_1.mpCompileDirPath}=this.compilerProps,compilerType=this.getCompilerType(entryType),projectPath=this.project.projectPath,basename=path_1.default.basename(projectPath),hash=(0,utils_1.getMd5)(projectPath).slice(0,8),distDir=path_1.default.join(path_1.default.resolve(compileDistDir,`${basename}_${hash}`),compilerType);return fs_extra_1.default.ensureDirSync(distDir),distDir}removeDistDir(entryType=constant_config_1.COMPILE_ENTRY.simulator){try{const distDir=this.getDistDir(entryType);fs_extra_1.default.existsSync(distDir)&&fs_extra_1.default.removeSync(distDir)}catch(error){}}getCacheDir(entryType=constant_config_1.COMPILE_ENTRY.simulator){const{compileCacheDir:compileCacheDir=dir_config_1.mpCompileCachePath}=this.compilerProps,projectPath=this.project.projectPath,compilerType=this.getCompilerType(entryType),basename=path_1.default.basename(projectPath),hash=(0,utils_1.getMd5)(projectPath).slice(0,8),distDir=path_1.default.join(path_1.default.resolve(compileCacheDir,`${basename}_${hash}`),compilerType);return fs_extra_1.default.ensureDirSync(distDir),distDir}removeCacheDir(entryType=constant_config_1.COMPILE_ENTRY.simulator){const cacheDir=this.getCacheDir(entryType);fs_extra_1.default.existsSync(cacheDir)&&fs_extra_1.default.removeSync(cacheDir)}removeAllCacheDir(){const cacheDir=this.getCacheDir(),parenCacheDir=path_1.default.dirname(cacheDir);fs_extra_1.default.existsSync(parenCacheDir)&&fs_extra_1.default.removeSync(parenCacheDir)}createCompiler(entryType=constant_config_1.COMPILE_ENTRY.simulator){const{nodeJsPath:nodeJsPath}=this.compilerProps,distDir=this.getDistDir(entryType),cacheDir=this.getCacheDir(entryType),compilerType=this.getCompilerType(entryType),options={packMode:compilerType===constant_config_1.COMPILER_TYPE.legacy_dev||compilerType===constant_config_1.COMPILER_TYPE.legacy_build?"webpack":"mp-pack",projectPath:this.project.projectPath,appMode:this.project.appMode,extJsonPath:this.project.extJsonDir,platform:"xhs",distDir:distDir,enablePersistCache:entryType!==constant_config_1.COMPILE_ENTRY.upload,cacheDirectory:cacheDir};this.removeDistDir(entryType);return new((0,compiler_1.getProjectCompilerClass)(compilerType))(options,{workerType:entryType===constant_config_1.COMPILE_ENTRY.simulator?"web":"process",nodeJsPath:nodeJsPath})}getUsingPackageType(){return __awaiter(this,arguments,void 0,(function*(entryType=constant_config_1.COMPILE_ENTRY.simulator){return{enableV1:!0,enableV2:!1,enableVDom:!0}}))}makePkgsReady(opts){return __awaiter(this,void 0,void 0,(function*(){var _a,_b;const{compilePkgs:compilePkgs}=opts,entryType=constant_config_1.COMPILE_ENTRY.simulator,defaultOptions=yield this.getUsingPackageType(entryType),compiler=this.getCompiler(entryType),startTime=Date.now();if(null==compilePkgs?void 0:compilePkgs.includes(constant_config_1.MAIN_PKG_ROOT)){const customEntry=this.project.customEntry,subPkg=this.project.getSubPackages().find((item=>customEntry.startsWith(`${item.root}/`)));subPkg&&!subPkg.independent&&compilePkgs.push(subPkg.root)}const config=Object.assign(Object.assign(Object.assign({compressCss:!1,compressJs:!0,enableSourcemap:!0,appendSourcemapComment:!0,devWriteToDisk:!0},defaultOptions),opts),{compilePkgs:compilePkgs});try{yield compiler.makePkgsReady(config),null===(_a=this.report)||void 0===_a||_a.call(this,"compile",{result:"success",entryType:entryType,config:JSON.stringify(config),duration:Date.now()-startTime})}catch(error){throw null===(_b=this.report)||void 0===_b||_b.call(this,"compile",{result:"fail",entryType:entryType,config:JSON.stringify(config),reason:null==error?void 0:error.message}),error}}))}reCompilePkgs(opts){return __awaiter(this,void 0,void 0,(function*(){var _a,_b,_c;const entryType=constant_config_1.COMPILE_ENTRY.simulator,compiler=this.getCompiler(entryType),defaultOptions=yield this.getUsingPackageType(entryType),startTime=Date.now(),config=Object.assign(Object.assign({compressCss:!1,compressJs:!0,enableSourcemap:!0,appendSourcemapComment:!0,devWriteToDisk:!0},defaultOptions),opts);try{this.removeCacheDir(),this.removeDistDir(),null===(_a=(0,sharedFs_1.default)(!0))||void 0===_a||_a.clear(),yield compiler.reCompilePkgs(config),null===(_b=this.report)||void 0===_b||_b.call(this,"compile",{result:"success",entryType:entryType,config:JSON.stringify(config),duration:Date.now()-startTime})}catch(error){throw null===(_c=this.report)||void 0===_c||_c.call(this,"compile",{result:"fail",entryType:entryType,config:JSON.stringify(config),reason:null==error?void 0:error.message}),error}}))}compileProject(config){return __awaiter(this,void 0,void 0,(function*(){var _a,_b,_c,_d;const{entryType:entryType}=config;try{this.emit("full-compile-project-start"),null===(_a=this.logger)||void 0===_a||_a.log("Compile project...");const startTime=Date.now(),compiler=this.getCompiler(entryType);this.removeDistDir(entryType),yield compiler.build(config),null===(_b=this.logger)||void 0===_b||_b.log("Compile project done..."),this.emit("full-compile-project-end"),null===(_c=this.report)||void 0===_c||_c.call(this,"compile",{result:"success",entryType:entryType,config:JSON.stringify(config),duration:Date.now()-startTime})}catch(error){throw null===(_d=this.report)||void 0===_d||_d.call(this,"compile",{result:"fail",entryType:entryType,config:JSON.stringify(config),reason:error.message}),error}}))}compileAndZip(opts){return new Promise(((resolve,reject)=>__awaiter(this,void 0,void 0,(function*(){var _a;const{can_upload_ext_json:can_upload_ext_json,entryType:entryType}=opts;try{const appJsonContent=this.project.appJsonContent,settings=this.project.settings||{};let subPackages=appJsonContent.subPackages||appJsonContent.subpackages||[];this.project.appMode===constant_config_1.MiniMode.minigame&&(subPackages=this.project.formatGameAppJSON(subPackages));const{enableV1:enableV1,enableV2:enableV2,enableVDom:enableVDom}=yield this.getUsingPackageType(entryType);let compressJs=!1,compressCss=!1,enableSourcemap=!0,appendSourcemapComment=!0;entryType===constant_config_1.COMPILE_ENTRY.preview?(compressCss=!0,compressJs=!0,enableSourcemap=!1,appendSourcemapComment=!1):entryType===constant_config_1.COMPILE_ENTRY.upload?(compressCss=!0,compressJs=!0,enableSourcemap=!0,appendSourcemapComment=!1):entryType===constant_config_1.COMPILE_ENTRY.remotedebug?(compressCss=!1,compressJs=!1,enableSourcemap=!0,appendSourcemapComment=!0):(compressCss=!1,compressJs=null!==(_a=settings.minified)&&void 0!==_a&&_a);const buildConfig=Object.assign({entryType:entryType,compressCss:compressCss,compressJs:compressJs,enableSourcemap:enableSourcemap,appendSourcemapComment:appendSourcemapComment,enableV1:enableV1,enableV2:enableV2,enableVDom:enableVDom,mpUploadOptions:this.project.appMode!==constant_config_1.MiniMode.minigame&&opts},opts);this.emit("compile-and-zip-status",{status:"build-start"}),yield this.compileProject(buildConfig),this.emit("compile-and-zip-status",{status:"build-done"}),this.emit("compile-and-zip-status",{status:"zip-start"});let entryZips=[];entryZips=entryType===constant_config_1.COMPILE_ENTRY.preview?[this.zipWithSubPackage(opts,subPackages,"v1"),buildConfig.enableV2&&this.zipWithSubPackage(opts,subPackages,"v2")]:entryType===constant_config_1.COMPILE_ENTRY.upload?[this.zipWithSubPackage(opts,subPackages,"v1",!0),enableV2&&this.zipWithSubPackage(opts,subPackages,"v2",!0)]:[this.zipWithSubPackage(opts,subPackages,enableV2?"v2":"v1")];const zipResult=(yield Promise.all(entryZips.filter(Boolean))).flat(2);if(this.emit("compile-and-zip-status",{status:"zip-done"}),this.project.appMode===constant_config_1.MiniMode.miniwidget){return this.checkMiniWidgetSize(zipResult,resolve,reject)}resolve(zipResult)}catch(error){reject(error)}}))))}checkMiniWidgetSize(zipResult,resolve,reject){if(this.project.appMode!==constant_config_1.MiniMode.miniwidget){return}for(const element of zipResult){if(element.zipSize>2097152){const error=new Error(`包体积过大,请检查代码,当前包体积大小 ${(0,file_1.fileSize)(element.zipSize)} 超过 ${(0,file_1.fileSize)(2097152)} 上限,请删除无用代码以及无用媒体资源`);return error.stack="",reject(error)}}return resolve(zipResult)}closeCompiler(entryType=constant_config_1.COMPILE_ENTRY.simulator){const compiler=this.compilerImplMap[entryType];compiler&&compiler.close()}killCompiler(entryType=constant_config_1.COMPILE_ENTRY.simulator){const compiler=this.compilerImplMap[entryType];compiler&&(compiler.kill(),delete this.compilerImplMap[entryType])}killAll(){Object.values(this.compilerImplMap).forEach((compiler=>{compiler.kill()})),this.compilerImplMap={}}zipWithSubPackage(opts,subPackages,type,excludeSourcemap){return __awaiter(this,void 0,void 0,(function*(){const projectConfig=this.project,{can_upload_ext_json:can_upload_ext_json,pkgInfo:pkgInfo,entryType:entryType}=opts,isRemoteDebug=entryType===constant_config_1.COMPILE_ENTRY.remotedebug,appendFile=[],appendBuffer=[];appendFile.push(projectConfig.projectJsonPath);const buildDir=this.getDistDir(entryType),mainEntry=path_1.default.resolve(buildDir,type),mainIgnore=(subPackages||[]).map((item=>item.root.endsWith("/")?`${item.root}**`:`${item.root}/**`)),subIgnore=[];if(excludeSourcemap&&(mainIgnore.push("**/*.map"),subIgnore.push("**/*.map")),can_upload_ext_json&&fs_extra_1.default.existsSync(projectConfig.extJsonPath)&&appendFile.push(projectConfig.extJsonPath),pkgInfo){const content={version:pkgInfo.version},contentStr=JSON.stringify(content);appendBuffer.push({name:"pkgInfo.json",buffer:Buffer.from(contentStr,"utf-8")})}const tasks=[];return tasks.push((0,project_1.zipFactory)({inputDir:mainEntry,type:type,prefix:"",meta:{root:"/"},pattern:"**/*",ignore:mainIgnore,appendFile:appendFile,appendBuffer:appendBuffer,outputDir:path_1.default.resolve(buildDir,`${type}-main-pack.zip`)})),(subPackages||[]).forEach(((item,index)=>{const pkgRoot=item.root.replace(/\//g,constant_config_1.PKG_ROOT_SEP);tasks.push((0,project_1.zipFactory)({inputDir:path_1.default.resolve(buildDir,type,item.root),prefix:`${item.root}`,appendFile:[],appendBuffer:[],pattern:"**/*",ignore:subIgnore,type:type,meta:{root:item.root},outputDir:path_1.default.resolve(buildDir,`${type}-sub-pack-${isRemoteDebug?pkgRoot:index}.zip`)}))})),excludeSourcemap&&tasks.push((0,project_1.zipFactory)({inputDir:mainEntry,pattern:"**/*.map",ignore:[],appendFile:[],appendBuffer:[],type:type,prefix:"",meta:{root:"/"},outputDir:path_1.default.resolve(buildDir,`${type}-pack-sourcemap.zip`)})),Promise.all(tasks)}))}}exports.ProjectCompilerManager=ProjectCompilerManager}));
1
+ var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){return new(P||(P=Promise))((function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator.throw(value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):function adopt(value){return value instanceof P?value:new P((function(resolve){resolve(value)}))}(result.value).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())}))},__importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};!function(factory){if("object"==typeof module&&"object"==typeof module.exports){var v=factory(require,exports);void 0!==v&&(module.exports=v)}else{"function"==typeof define&&define.amd&&define(["require","exports","./config/constant.config","xhs-mp-project","events","fs-extra","path","./utils/utils","./utils/project","./utils/file","./config/dir.config","./compiler","./sharedFs"],factory)}}((function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ProjectCompilerManager=exports.prepareDevPool=exports.COMPILE_ENTRY=void 0;const constant_config_1=require("./config/constant.config");Object.defineProperty(exports,"COMPILE_ENTRY",{enumerable:!0,get:function(){return constant_config_1.COMPILE_ENTRY}});const xhs_mp_project_1=require("xhs-mp-project"),events_1=__importDefault(require("events")),fs_extra_1=__importDefault(require("fs-extra")),path_1=__importDefault(require("path")),utils_1=require("./utils/utils"),project_1=require("./utils/project"),file_1=require("./utils/file"),dir_config_1=require("./config/dir.config"),compiler_1=require("./compiler");Object.defineProperty(exports,"prepareDevPool",{enumerable:!0,get:function(){return compiler_1.prepareDevPool}});const sharedFs_1=__importDefault(require("./sharedFs"));class ProjectCompilerManager extends events_1.default{constructor(props){super(),this.compilerImplMap={},this.getCompiler=(entryType=constant_config_1.COMPILE_ENTRY.simulator)=>(this.compilerImplMap[entryType]||(this.compilerImplMap[entryType]=this.createCompiler(entryType),entryType===constant_config_1.COMPILE_ENTRY.simulator?this.initSimulatorCompiler(this.compilerImplMap[entryType]):this.initBuildCompiler(this.compilerImplMap[entryType])),this.compilerImplMap[entryType]),this.initSimulatorCompiler=compiler=>{compiler.on("buildStart",(data=>{this.emit("simulator-compile-start",data)})),compiler.on("buildEnd",(data=>{this.emit("simulator-compile-end",data)})),compiler.on("compileInfo",(data=>{this.emit("simulator-compile-info",data)})),compiler.on("compilePercent",(data=>{this.emit("simulator-compile-percent",data)})),compiler.on("compileErrorWhenFileChange",(error=>{this.emit("simulator-file-change-compile-error",error)})),compiler.on("compileFinishWhenFileChange",(data=>{this.emit("simulator-file-change-compile-finish",data)})),compiler.on("uncaughtException",(err=>{this.emit("simulator-uncaught-exception",err)}))},this.initBuildCompiler=compiler=>{compiler.on("compilePercent",(data=>{this.emit("full-compile-percent",data)})),compiler.on("compileInfo",(data=>{this.emit("full-compiler-info",data)})),compiler.on("uncaughtException",(err=>{this.emit("full-compile-uncaught-exception",err)}))};const{logger:logger,report:report,projectPath:projectPath,project:project}=props;this.logger=logger||console,this.report=report,this.compilerProps=props,(project||projectPath)&&(this.project=project||new xhs_mp_project_1.Project({projectPath:projectPath}))}bindProject(props){const{projectPath:projectPath,project:project}=props;if(!project&&!projectPath){throw new Error("project 和 projectPath 均为undefined")}this.project=project||new xhs_mp_project_1.Project({projectPath:projectPath})}getCompilerType(entryType=constant_config_1.COMPILE_ENTRY.simulator){const isGame=this.project.appMode===constant_config_1.MiniMode.minigame,settings=this.project.settings||{};return isGame||!settings.useNewCompiler?entryType===constant_config_1.COMPILE_ENTRY.simulator?constant_config_1.COMPILER_TYPE.legacy_dev:constant_config_1.COMPILER_TYPE.legacy_build:entryType===constant_config_1.COMPILE_ENTRY.simulator?constant_config_1.COMPILER_TYPE.dev:entryType===constant_config_1.COMPILE_ENTRY.upload?constant_config_1.COMPILER_TYPE.legacy_build:constant_config_1.COMPILER_TYPE.build}getDistDir(entryType=constant_config_1.COMPILE_ENTRY.simulator){const{compileDistDir:compileDistDir=dir_config_1.mpCompileDirPath}=this.compilerProps,compilerType=this.getCompilerType(entryType),projectPath=this.project.projectPath,basename=path_1.default.basename(projectPath),hash=(0,utils_1.getMd5)(projectPath).slice(0,8),distDir=path_1.default.join(path_1.default.resolve(compileDistDir,`${basename}_${hash}`),compilerType);return fs_extra_1.default.ensureDirSync(distDir),distDir}removeDistDir(entryType=constant_config_1.COMPILE_ENTRY.simulator){try{const distDir=this.getDistDir(entryType);fs_extra_1.default.existsSync(distDir)&&fs_extra_1.default.removeSync(distDir)}catch(error){}}getCacheDir(entryType=constant_config_1.COMPILE_ENTRY.simulator){const{compileCacheDir:compileCacheDir=dir_config_1.mpCompileCachePath}=this.compilerProps,projectPath=this.project.projectPath,compilerType=this.getCompilerType(entryType),basename=path_1.default.basename(projectPath),hash=(0,utils_1.getMd5)(projectPath).slice(0,8),distDir=path_1.default.join(path_1.default.resolve(compileCacheDir,`${basename}_${hash}`),compilerType);return fs_extra_1.default.ensureDirSync(distDir),distDir}removeCacheDir(entryType=constant_config_1.COMPILE_ENTRY.simulator){const cacheDir=this.getCacheDir(entryType);fs_extra_1.default.existsSync(cacheDir)&&fs_extra_1.default.removeSync(cacheDir)}removeAllCacheDir(){const cacheDir=this.getCacheDir(),parenCacheDir=path_1.default.dirname(cacheDir);fs_extra_1.default.existsSync(parenCacheDir)&&fs_extra_1.default.removeSync(parenCacheDir)}createCompiler(entryType=constant_config_1.COMPILE_ENTRY.simulator){const{nodeJsPath:nodeJsPath}=this.compilerProps,distDir=this.getDistDir(entryType),cacheDir=this.getCacheDir(entryType),compilerType=this.getCompilerType(entryType),options={packMode:compilerType===constant_config_1.COMPILER_TYPE.legacy_dev||compilerType===constant_config_1.COMPILER_TYPE.legacy_build?"webpack":"mp-pack",projectPath:this.project.projectPath,appMode:this.project.appMode,extJsonPath:this.project.extJsonDir,platform:"xhs",distDir:distDir,enablePersistCache:entryType!==constant_config_1.COMPILE_ENTRY.upload,cacheDirectory:cacheDir};this.removeDistDir(entryType);return new((0,compiler_1.getProjectCompilerClass)(compilerType))(options,{workerType:entryType===constant_config_1.COMPILE_ENTRY.simulator?"web":"process",nodeJsPath:nodeJsPath})}getUsingPackageType(){return __awaiter(this,arguments,void 0,(function*(entryType=constant_config_1.COMPILE_ENTRY.simulator){return{enableV1:!0,enableV2:!1,enableVDom:!0}}))}makePkgsReady(opts){return __awaiter(this,void 0,void 0,(function*(){var _a,_b;const{compilePkgs:compilePkgs}=opts,entryType=constant_config_1.COMPILE_ENTRY.simulator,defaultOptions=yield this.getUsingPackageType(entryType),compiler=this.getCompiler(entryType),startTime=Date.now();if(null==compilePkgs?void 0:compilePkgs.includes(constant_config_1.MAIN_PKG_ROOT)){const customEntry=this.project.customEntry,subPkg=this.project.getSubPackages().find((item=>customEntry.startsWith(`${item.root}/`)));subPkg&&!subPkg.independent&&compilePkgs.push(subPkg.root)}const config=Object.assign(Object.assign(Object.assign({compressCss:!1,compressJs:!0,enableSourcemap:!0,appendSourcemapComment:!0,devWriteToDisk:!0},defaultOptions),opts),{compilePkgs:compilePkgs,entryType:entryType});try{yield compiler.makePkgsReady(config),null===(_a=this.report)||void 0===_a||_a.call(this,"compile",{result:"success",entryType:entryType,config:JSON.stringify(config),duration:Date.now()-startTime})}catch(error){throw null===(_b=this.report)||void 0===_b||_b.call(this,"compile",{result:"fail",entryType:entryType,config:JSON.stringify(config),reason:null==error?void 0:error.message}),error}}))}reCompilePkgs(opts){return __awaiter(this,void 0,void 0,(function*(){var _a,_b,_c;const entryType=constant_config_1.COMPILE_ENTRY.simulator,compiler=this.getCompiler(entryType),defaultOptions=yield this.getUsingPackageType(entryType),startTime=Date.now(),config=Object.assign(Object.assign(Object.assign({compressCss:!1,compressJs:!0,enableSourcemap:!0,appendSourcemapComment:!0,devWriteToDisk:!0},defaultOptions),opts),{entryType:entryType});try{this.removeCacheDir(),this.removeDistDir(),null===(_a=(0,sharedFs_1.default)(!0))||void 0===_a||_a.clear(),yield compiler.reCompilePkgs(config),null===(_b=this.report)||void 0===_b||_b.call(this,"compile",{result:"success",entryType:entryType,config:JSON.stringify(config),duration:Date.now()-startTime})}catch(error){throw null===(_c=this.report)||void 0===_c||_c.call(this,"compile",{result:"fail",entryType:entryType,config:JSON.stringify(config),reason:null==error?void 0:error.message}),error}}))}compileProject(config){return __awaiter(this,void 0,void 0,(function*(){var _a,_b,_c,_d;const{entryType:entryType}=config;try{this.emit("full-compile-project-start"),null===(_a=this.logger)||void 0===_a||_a.log("Compile project...");const startTime=Date.now(),compiler=this.getCompiler(entryType);this.removeDistDir(entryType),yield compiler.build(config),null===(_b=this.logger)||void 0===_b||_b.log("Compile project done..."),this.emit("full-compile-project-end"),null===(_c=this.report)||void 0===_c||_c.call(this,"compile",{result:"success",entryType:entryType,config:JSON.stringify(config),duration:Date.now()-startTime})}catch(error){throw null===(_d=this.report)||void 0===_d||_d.call(this,"compile",{result:"fail",entryType:entryType,config:JSON.stringify(config),reason:error.message}),error}}))}compileAndZip(opts){return new Promise(((resolve,reject)=>__awaiter(this,void 0,void 0,(function*(){var _a;const{can_upload_ext_json:can_upload_ext_json,entryType:entryType}=opts;try{const appJsonContent=this.project.appJsonContent,settings=this.project.settings||{};let subPackages=appJsonContent.subPackages||appJsonContent.subpackages||[];this.project.appMode===constant_config_1.MiniMode.minigame&&(subPackages=this.project.formatGameAppJSON(subPackages));const{enableV1:enableV1,enableV2:enableV2,enableVDom:enableVDom}=yield this.getUsingPackageType(entryType);let compressJs=!1,compressCss=!1,enableSourcemap=!0,appendSourcemapComment=!0;entryType===constant_config_1.COMPILE_ENTRY.preview?(compressCss=!0,compressJs=!0,enableSourcemap=!1,appendSourcemapComment=!1):entryType===constant_config_1.COMPILE_ENTRY.upload?(compressCss=!0,compressJs=!0,enableSourcemap=!0,appendSourcemapComment=!1):entryType===constant_config_1.COMPILE_ENTRY.remotedebug?(compressCss=!1,compressJs=!1,enableSourcemap=!0,appendSourcemapComment=!0):(compressCss=!1,compressJs=null!==(_a=settings.minified)&&void 0!==_a&&_a);const buildConfig=Object.assign({entryType:entryType,compressCss:compressCss,compressJs:compressJs,enableSourcemap:enableSourcemap,appendSourcemapComment:appendSourcemapComment,enableV1:enableV1,enableV2:enableV2,enableVDom:enableVDom,mpUploadOptions:this.project.appMode!==constant_config_1.MiniMode.minigame&&opts},opts);this.emit("compile-and-zip-status",{status:"build-start"}),yield this.compileProject(buildConfig),this.emit("compile-and-zip-status",{status:"build-done"}),this.emit("compile-and-zip-status",{status:"zip-start"});let entryZips=[];entryZips=entryType===constant_config_1.COMPILE_ENTRY.preview?[this.zipWithSubPackage(opts,subPackages,"v1"),buildConfig.enableV2&&this.zipWithSubPackage(opts,subPackages,"v2")]:entryType===constant_config_1.COMPILE_ENTRY.upload?[this.zipWithSubPackage(opts,subPackages,"v1",!0),enableV2&&this.zipWithSubPackage(opts,subPackages,"v2",!0)]:[this.zipWithSubPackage(opts,subPackages,enableV2?"v2":"v1")];const zipResult=(yield Promise.all(entryZips.filter(Boolean))).flat(2);if(this.emit("compile-and-zip-status",{status:"zip-done"}),this.project.appMode===constant_config_1.MiniMode.miniwidget){return this.checkMiniWidgetSize(zipResult,resolve,reject)}resolve(zipResult)}catch(error){reject(error)}}))))}checkMiniWidgetSize(zipResult,resolve,reject){if(this.project.appMode!==constant_config_1.MiniMode.miniwidget){return}for(const element of zipResult){if(element.zipSize>2097152){const error=new Error(`包体积过大,请检查代码,当前包体积大小 ${(0,file_1.fileSize)(element.zipSize)} 超过 ${(0,file_1.fileSize)(2097152)} 上限,请删除无用代码以及无用媒体资源`);return error.stack="",reject(error)}}return resolve(zipResult)}closeCompiler(entryType=constant_config_1.COMPILE_ENTRY.simulator){const compiler=this.compilerImplMap[entryType];compiler&&compiler.close()}killCompiler(entryType=constant_config_1.COMPILE_ENTRY.simulator){const compiler=this.compilerImplMap[entryType];compiler&&(compiler.kill(),delete this.compilerImplMap[entryType])}killAll(){Object.values(this.compilerImplMap).forEach((compiler=>{compiler.kill()})),this.compilerImplMap={}}zipWithSubPackage(opts,subPackages,type,excludeSourcemap){return __awaiter(this,void 0,void 0,(function*(){const projectConfig=this.project,{can_upload_ext_json:can_upload_ext_json,pkgInfo:pkgInfo,entryType:entryType}=opts,isRemoteDebug=entryType===constant_config_1.COMPILE_ENTRY.remotedebug,appendFile=[],appendBuffer=[];appendFile.push(projectConfig.projectJsonPath);const buildDir=this.getDistDir(entryType),mainEntry=path_1.default.resolve(buildDir,type),mainIgnore=(subPackages||[]).map((item=>item.root.endsWith("/")?`${item.root}**`:`${item.root}/**`)),subIgnore=[];if(excludeSourcemap&&(mainIgnore.push("**/*.map"),subIgnore.push("**/*.map")),can_upload_ext_json&&fs_extra_1.default.existsSync(projectConfig.extJsonPath)&&appendFile.push(projectConfig.extJsonPath),pkgInfo){const content={version:pkgInfo.version},contentStr=JSON.stringify(content);appendBuffer.push({name:"pkgInfo.json",buffer:Buffer.from(contentStr,"utf-8")})}const tasks=[];return tasks.push((0,project_1.zipFactory)({inputDir:mainEntry,type:type,prefix:"",meta:{root:"/"},pattern:"**/*",ignore:mainIgnore,appendFile:appendFile,appendBuffer:appendBuffer,outputDir:path_1.default.resolve(buildDir,`${type}-main-pack.zip`)})),(subPackages||[]).forEach(((item,index)=>{const pkgRoot=item.root.replace(/\//g,constant_config_1.PKG_ROOT_SEP);tasks.push((0,project_1.zipFactory)({inputDir:path_1.default.resolve(buildDir,type,item.root),prefix:`${item.root}`,appendFile:[],appendBuffer:[],pattern:"**/*",ignore:subIgnore,type:type,meta:{root:item.root},outputDir:path_1.default.resolve(buildDir,`${type}-sub-pack-${isRemoteDebug?pkgRoot:index}.zip`)}))})),excludeSourcemap&&tasks.push((0,project_1.zipFactory)({inputDir:mainEntry,pattern:"**/*.map",ignore:[],appendFile:[],appendBuffer:[],type:type,prefix:"",meta:{root:"/"},outputDir:path_1.default.resolve(buildDir,`${type}-pack-sourcemap.zip`)})),Promise.all(tasks)}))}}exports.ProjectCompilerManager=ProjectCompilerManager}));
@@ -1 +1 @@
1
- var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};!function(factory){if("object"==typeof module&&"object"==typeof module.exports){var v=factory(require,exports);void 0!==v&&(module.exports=v)}else{"function"==typeof define&&define.amd&&define(["require","exports","../../presets","path","xhs-mp-pack","../../utils/apm","../../config/constant.config"],factory)}}((function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createCompiler=void 0;const presets_1=require("../../presets"),path_1=__importDefault(require("path")),xhs_mp_pack_1=require("xhs-mp-pack"),apm_1=require("../../utils/apm"),constant_config_1=require("../../config/constant.config");exports.createCompiler=startConfig=>{const mppack=new xhs_mp_pack_1.MPPack(startConfig),compilerOptions={project:mppack.project,packSetting:mppack.packSetting,packMode:constant_config_1.PACK_MODE.MPPACK,reporter:(0,apm_1.createReporter)(mppack.project,startConfig.mpUploadOptions)},mpPackConfigs=(0,presets_1.createConfigs)(compilerOptions);return mpPackConfigs.forEach((config=>{var _a,_b,_c,_d;null===(_b=null===(_a=config.resolve)||void 0===_a?void 0:_a.modules)||void 0===_b||_b.push(path_1.default.resolve(__dirname,"../../../../")),null===(_d=null===(_c=config.resolve)||void 0===_c?void 0:_c.modules)||void 0===_d||_d.push(path_1.default.resolve(__dirname,"../../"))})),mppack.createCompiler(mpPackConfigs),mppack}}));
1
+ var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};!function(factory){if("object"==typeof module&&"object"==typeof module.exports){var v=factory(require,exports);void 0!==v&&(module.exports=v)}else{"function"==typeof define&&define.amd&&define(["require","exports","../../presets","path","xhs-mp-pack","../../utils/apm","../../config/constant.config"],factory)}}((function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createCompiler=void 0;const presets_1=require("../../presets"),path_1=__importDefault(require("path")),xhs_mp_pack_1=require("xhs-mp-pack"),apm_1=require("../../utils/apm"),constant_config_1=require("../../config/constant.config");exports.createCompiler=startConfig=>{const mppack=new xhs_mp_pack_1.MPPack(startConfig),compilerOptions={project:mppack.project,packSetting:mppack.packSetting,packMode:constant_config_1.PACK_MODE.MPPACK,reporter:(0,apm_1.createReporter)(mppack.project,startConfig.mpUploadOptions),entryType:startConfig.entryType},mpPackConfigs=(0,presets_1.createConfigs)(compilerOptions);return mpPackConfigs.forEach((config=>{var _a,_b,_c,_d;null===(_b=null===(_a=config.resolve)||void 0===_a?void 0:_a.modules)||void 0===_b||_b.push(path_1.default.resolve(__dirname,"../../../../")),null===(_d=null===(_c=config.resolve)||void 0===_c?void 0:_c.modules)||void 0===_d||_d.push(path_1.default.resolve(__dirname,"../../"))})),mppack.createCompiler(mpPackConfigs),mppack}}));
@@ -1 +1 @@
1
- var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};!function(factory){if("object"==typeof module&&"object"==typeof module.exports){var v=factory(require,exports);void 0!==v&&(module.exports=v)}else{"function"==typeof define&&define.amd&&define(["require","exports","path","fs-extra","../../utils/projectConfig","../../utils/common","../../presets","xhs-mp-project","xhs-mp-pack","./webpack","../../utils/apm","../../config/constant.config","xhs-mp-compiler-utils"],factory)}}((function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createPacker=void 0;const path_1=__importDefault(require("path")),fs_extra_1=__importDefault(require("fs-extra")),projectConfig_1=require("../../utils/projectConfig"),common_1=require("../../utils/common"),presets_1=require("../../presets"),xhs_mp_project_1=require("xhs-mp-project"),xhs_mp_pack_1=require("xhs-mp-pack"),webpack_1=require("./webpack"),apm_1=require("../../utils/apm"),constant_config_1=require("../../config/constant.config"),xhs_mp_compiler_utils_1=require("xhs-mp-compiler-utils");exports.createPacker=startConfig=>{const{projectPath:projectPath}=startConfig;startConfig=(startConfig=>{const{projectPath:projectPath,action:action,tsConfigPath:tsConfigPath,platform:platform,compressCss:compressCss=!0,compressJs:compressJs=!0,enableSourcemap:enableSourcemap=!0,appendSourcemapComment:appendSourcemapComment=!0,mpUploadOptions:mpUploadOptions=!1}=startConfig,{enableV1:enableV1,enableV2:enableV2,enableVDom:enableVDom}=(startConfig=>{let{action:action,enableV1:enableV1=!0,enableV2:enableV2=!1,enableVDom:enableVDom=!1}=startConfig;return"build"===action&&(enableV1=!0),enableV1||enableV2||(enableV1=!0,enableV2=!1),{enableV1:enableV1,enableV2:enableV2,enableVDom:enableVDom}})(startConfig),distDir=startConfig.distDir||path_1.default.join(process.cwd(),"dist");process.env.__platform=platform;try{fs_extra_1.default.existsSync(distDir)&&fs_extra_1.default.rmSync(distDir,{recursive:!0})}catch(error){}const projectJson=(0,projectConfig_1.getProjectConfig)(projectPath);let miniprogramDir=path_1.default.join(projectPath,projectJson.miniprogramRoot||"");return miniprogramDir=miniprogramDir.endsWith("/")?miniprogramDir.slice(0,-1):miniprogramDir,{projectPath:(0,xhs_mp_compiler_utils_1.toUnixPath)(projectPath),miniprogramDir:(0,xhs_mp_compiler_utils_1.toUnixPath)(miniprogramDir).replace(/\/+$/,""),distDir:distDir,action:action,tsConfigPath:tsConfigPath||(0,common_1.getTsConfigPath)(projectPath),cacheDirectory:startConfig.cacheDirectory,compressCss:compressCss,compressJs:compressJs,enableSourcemap:enableSourcemap,appendSourcemapComment:appendSourcemapComment,enableV1:enableV1,enableV2:enableV2,enableVDom:enableVDom,mpUploadOptions:mpUploadOptions}})(startConfig);const project=new xhs_mp_project_1.Project({projectPath:projectPath}),compilerOptions={project:project,packSetting:new xhs_mp_pack_1.MPPackSetting(project,startConfig),packMode:constant_config_1.PACK_MODE.WEBPACK,reporter:(0,apm_1.createReporter)(project,startConfig.mpUploadOptions)},webpackConfig=(0,presets_1.createConfigs)(compilerOptions);return webpackConfig.forEach((config=>{var _a,_b,_c,_d;null===(_b=null===(_a=config.resolve)||void 0===_a?void 0:_a.modules)||void 0===_b||_b.push(path_1.default.resolve(__dirname,"../../../../")),null===(_d=null===(_c=config.resolve)||void 0===_c?void 0:_c.modules)||void 0===_d||_d.push(path_1.default.resolve(__dirname,"../../../"))})),new webpack_1.WebPack(webpackConfig,compilerOptions)}}));
1
+ var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};!function(factory){if("object"==typeof module&&"object"==typeof module.exports){var v=factory(require,exports);void 0!==v&&(module.exports=v)}else{"function"==typeof define&&define.amd&&define(["require","exports","path","fs-extra","../../utils/projectConfig","../../utils/common","../../presets","xhs-mp-project","xhs-mp-pack","./webpack","../../utils/apm","../../config/constant.config","xhs-mp-compiler-utils"],factory)}}((function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createPacker=void 0;const path_1=__importDefault(require("path")),fs_extra_1=__importDefault(require("fs-extra")),projectConfig_1=require("../../utils/projectConfig"),common_1=require("../../utils/common"),presets_1=require("../../presets"),xhs_mp_project_1=require("xhs-mp-project"),xhs_mp_pack_1=require("xhs-mp-pack"),webpack_1=require("./webpack"),apm_1=require("../../utils/apm"),constant_config_1=require("../../config/constant.config"),xhs_mp_compiler_utils_1=require("xhs-mp-compiler-utils");exports.createPacker=startConfig=>{const{projectPath:projectPath,entryType:entryType}=startConfig,formattedConfig=(startConfig=>{const{projectPath:projectPath,action:action,tsConfigPath:tsConfigPath,platform:platform,compressCss:compressCss=!0,compressJs:compressJs=!0,enableSourcemap:enableSourcemap=!0,appendSourcemapComment:appendSourcemapComment=!0,mpUploadOptions:mpUploadOptions=!1}=startConfig,{enableV1:enableV1,enableV2:enableV2,enableVDom:enableVDom}=(startConfig=>{let{action:action,enableV1:enableV1=!0,enableV2:enableV2=!1,enableVDom:enableVDom=!1}=startConfig;return"build"===action&&(enableV1=!0),enableV1||enableV2||(enableV1=!0,enableV2=!1),{enableV1:enableV1,enableV2:enableV2,enableVDom:enableVDom}})(startConfig),distDir=startConfig.distDir||path_1.default.join(process.cwd(),"dist");process.env.__platform=platform;try{fs_extra_1.default.existsSync(distDir)&&fs_extra_1.default.rmSync(distDir,{recursive:!0})}catch(error){}const projectJson=(0,projectConfig_1.getProjectConfig)(projectPath);let miniprogramDir=path_1.default.join(projectPath,projectJson.miniprogramRoot||"");return miniprogramDir=miniprogramDir.endsWith("/")?miniprogramDir.slice(0,-1):miniprogramDir,{projectPath:(0,xhs_mp_compiler_utils_1.toUnixPath)(projectPath),miniprogramDir:(0,xhs_mp_compiler_utils_1.toUnixPath)(miniprogramDir).replace(/\/+$/,""),distDir:distDir,action:action,tsConfigPath:tsConfigPath||(0,common_1.getTsConfigPath)(projectPath),cacheDirectory:startConfig.cacheDirectory,compressCss:compressCss,compressJs:compressJs,enableSourcemap:enableSourcemap,appendSourcemapComment:appendSourcemapComment,enableV1:enableV1,enableV2:enableV2,enableVDom:enableVDom,mpUploadOptions:mpUploadOptions}})(startConfig),project=new xhs_mp_project_1.Project({projectPath:projectPath}),compilerOptions={project:project,packSetting:new xhs_mp_pack_1.MPPackSetting(project,formattedConfig),packMode:constant_config_1.PACK_MODE.WEBPACK,reporter:(0,apm_1.createReporter)(project,formattedConfig.mpUploadOptions),entryType:entryType},webpackConfig=(0,presets_1.createConfigs)(compilerOptions);return webpackConfig.forEach((config=>{var _a,_b,_c,_d;null===(_b=null===(_a=config.resolve)||void 0===_a?void 0:_a.modules)||void 0===_b||_b.push(path_1.default.resolve(__dirname,"../../../../")),null===(_d=null===(_c=config.resolve)||void 0===_c?void 0:_c.modules)||void 0===_d||_d.push(path_1.default.resolve(__dirname,"../../../"))})),new webpack_1.WebPack(webpackConfig,compilerOptions)}}));
@@ -1 +1 @@
1
- var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};!function(factory){if("object"==typeof module&&"object"==typeof module.exports){var v=factory(require,exports);void 0!==v&&(module.exports=v)}else{"function"==typeof define&&define.amd&&define(["require","exports","path","xhs-mp-shared","./sjsEntryPlugin","./render","./component","./sketch","./renderChunkPlugin","../../../../types","../../../plugins/InjectorPlugin","../../../../utils/cache"],factory)}}((function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.presetRender=exports.getRenderEntry=void 0;const path_1=__importDefault(require("path")),xhs_mp_shared_1=require("xhs-mp-shared"),sjsEntryPlugin_1=__importDefault(require("./sjsEntryPlugin")),render_1=require("./render"),component_1=require("./component"),sketch_1=require("./sketch"),renderChunkPlugin_1=__importDefault(require("./renderChunkPlugin")),types_1=require("../../../../types"),InjectorPlugin_1=require("../../../plugins/InjectorPlugin"),cache_1=require("../../../../utils/cache");exports.getRenderEntry=options=>()=>Object.assign(Object.assign(Object.assign({},(0,render_1.getRenderEntry)(options)),(0,component_1.getComponentEntry)(options)),(0,sketch_1.getSketchEntry)(options));exports.presetRender=(chain,options)=>{const{packSetting:packSetting}=options,{enableVDom:enableVDom,env:env,distDir:distDir,cacheDirectory:cacheDirectory,enableSourcemap:enableSourcemap,appendSourcemapComment:appendSourcemapComment}=packSetting,isProd=env===types_1.ENV.production,absCacheDirectory=path_1.default.join(cacheDirectory,"render"),transfomLoader=isProd?{"swc-loader":{loader:require.resolve("swc-loader"),options:{jsc:{target:"es2019",externalHelpers:!1}}}}:{};chain.merge(Object.assign(Object.assign({externals:{vue:"vue"},output:{path:distDir,globalObject:"globalThis",libraryTarget:"umd",uniqueName:"MpRender"}},(0,cache_1.getCacheConfig)(absCacheDirectory,options)),{module:{rule:{ml:{test:xhs_mp_shared_1.ML_REG,use:Object.assign(Object.assign({},transfomLoader),{"ml-loader":{loader:require.resolve("xhs-mp-ml-loader"),options:{removeComentNode:isProd}}})},sketchMl:{test:xhs_mp_shared_1.SKETCH_ML_REG,use:Object.assign(Object.assign({},transfomLoader),{"sketch-loader":{loader:require.resolve("xhs-mp-sketch-loader"),options:{removeComentNode:isProd}}})},style:{test:xhs_mp_shared_1.CSS_REG,use:{"mini-style-loader":{loader:"mini-style-loader",options:{independentFile:enableVDom,emitDirs:[packSetting.enableV1&&"v1",packSetting.enableV2&&"v2"].filter(Boolean)}},"wxss-loader":{loader:"wxss-loader"}}},sketchStyle:{test:xhs_mp_shared_1.SKETCH_CSS_REG,use:{"string-loader":{loader:"string-loader"},"wxss-loader":{loader:"wxss-loader"}}}}}})),chain.plugin("InjectorPlugin").use(InjectorPlugin_1.InjectorPlugin,[options]),chain.plugin("SjsEntryPlugin").use(sjsEntryPlugin_1.default,[options]),chain.plugin("RenderChunkPlugin").use(renderChunkPlugin_1.default,[options])}}));
1
+ var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};!function(factory){if("object"==typeof module&&"object"==typeof module.exports){var v=factory(require,exports);void 0!==v&&(module.exports=v)}else{"function"==typeof define&&define.amd&&define(["require","exports","path","xhs-mp-shared","./sjsEntryPlugin","./render","./component","./sketch","./renderChunkPlugin","../../../../types","../../../plugins/InjectorPlugin","../../../../utils/cache"],factory)}}((function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.presetRender=exports.getRenderEntry=void 0;const path_1=__importDefault(require("path")),xhs_mp_shared_1=require("xhs-mp-shared"),sjsEntryPlugin_1=__importDefault(require("./sjsEntryPlugin")),render_1=require("./render"),component_1=require("./component"),sketch_1=require("./sketch"),renderChunkPlugin_1=__importDefault(require("./renderChunkPlugin")),types_1=require("../../../../types"),InjectorPlugin_1=require("../../../plugins/InjectorPlugin"),cache_1=require("../../../../utils/cache");exports.getRenderEntry=options=>()=>Object.assign(Object.assign(Object.assign({},(0,render_1.getRenderEntry)(options)),(0,component_1.getComponentEntry)(options)),(0,sketch_1.getSketchEntry)(options));exports.presetRender=(chain,options)=>{const{packSetting:packSetting,entryType:entryType}=options,{enableVDom:enableVDom,env:env,distDir:distDir,cacheDirectory:cacheDirectory,enableSourcemap:enableSourcemap,appendSourcemapComment:appendSourcemapComment}=packSetting,isProd=env===types_1.ENV.production,absCacheDirectory=path_1.default.join(cacheDirectory,"render"),transfomLoader=isProd?{"swc-loader":{loader:require.resolve("swc-loader"),options:{jsc:{target:"es2019",externalHelpers:!1}}}}:{};chain.merge(Object.assign(Object.assign({externals:{vue:"vue"},output:{path:distDir,globalObject:"globalThis",libraryTarget:"umd",uniqueName:"MpRender"}},(0,cache_1.getCacheConfig)(absCacheDirectory,options)),{module:{rule:{ml:{test:xhs_mp_shared_1.ML_REG,use:Object.assign(Object.assign({},transfomLoader),{"ml-loader":{loader:require.resolve("xhs-mp-ml-loader"),options:{removeComentNode:isProd,entryType:entryType}}})},sketchMl:{test:xhs_mp_shared_1.SKETCH_ML_REG,use:Object.assign(Object.assign({},transfomLoader),{"sketch-loader":{loader:require.resolve("xhs-mp-sketch-loader"),options:{removeComentNode:isProd}}})},style:{test:xhs_mp_shared_1.CSS_REG,use:{"mini-style-loader":{loader:"mini-style-loader",options:{independentFile:enableVDom,emitDirs:[packSetting.enableV1&&"v1",packSetting.enableV2&&"v2"].filter(Boolean)}},"wxss-loader":{loader:"wxss-loader"}}},sketchStyle:{test:xhs_mp_shared_1.SKETCH_CSS_REG,use:{"string-loader":{loader:"string-loader"},"wxss-loader":{loader:"wxss-loader"}}}}}})),chain.plugin("InjectorPlugin").use(InjectorPlugin_1.InjectorPlugin,[options]),chain.plugin("SjsEntryPlugin").use(sjsEntryPlugin_1.default,[options]),chain.plugin("RenderChunkPlugin").use(renderChunkPlugin_1.default,[options])}}));
@@ -64,6 +64,7 @@ export interface IStart extends Pick<ICompilerConfig, CliPick> {
64
64
  platform?: 'wx' | 'xhs';
65
65
  enableDevServer?: boolean;
66
66
  devServerPort?: number;
67
+ entryType?: string;
67
68
  }
68
69
  export type IPresetOptions = {
69
70
  packMode: string;
@@ -71,5 +72,6 @@ export type IPresetOptions = {
71
72
  packSetting: MPPackSetting;
72
73
  otherSetting?: any;
73
74
  reporter?: FeatureReporter.IReporter;
75
+ entryType?: string;
74
76
  };
75
77
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xhs-mp-compiler-cli",
3
- "version": "2.1.4",
3
+ "version": "2.1.6-beta.0",
4
4
  "description": "xhs mp command tool.",
5
5
  "preferGlobal": true,
6
6
  "category": "esm",
@@ -89,18 +89,18 @@
89
89
  "webpack-chain": "^6.5.1",
90
90
  "webpack-sources": "^3.2.2",
91
91
  "xhs-mp-workerpool": "^9.2.0",
92
- "xhs-mp-ml-loader": "2.1.4",
93
- "xhs-mp-compiler-utils": "2.1.4",
94
- "xhs-mp-pack": "2.1.4",
95
- "xhs-mp-project": "2.1.4",
96
- "xhs-mp-shared": "2.1.4",
97
- "xhs-mp-shared-fs": "2.1.4",
98
- "xhs-mp-sjs-loader": "2.1.4",
99
- "xhs-mp-sketch-loader": "2.1.4",
92
+ "xhs-mp-ml-loader": "2.1.6-beta.0",
93
+ "xhs-mp-compiler-utils": "2.1.6-beta.0",
94
+ "xhs-mp-pack": "2.1.6-beta.0",
95
+ "xhs-mp-project": "2.1.6-beta.0",
96
+ "xhs-mp-shared": "2.1.6-beta.0",
97
+ "xhs-mp-shared-fs": "2.1.6-beta.0",
98
+ "xhs-mp-sjs-loader": "2.1.6-beta.0",
99
+ "xhs-mp-sketch-loader": "2.1.6-beta.0",
100
100
  "yauzl": "^2.10.0"
101
101
  },
102
102
  "peerDependencies": {
103
- "xhs-mp-ml-parser": "2.1.4"
103
+ "xhs-mp-ml-parser": "2.1.6-beta.0"
104
104
  },
105
105
  "devDependencies": {
106
106
  "@types/babel__generator": "7.6.3",
@@ -123,7 +123,7 @@
123
123
  "@types/node": "14",
124
124
  "typescript": "5.1.6",
125
125
  "webpack-dev-server": "4.0.0-beta.3",
126
- "xhs-mp-ml-parser": "2.1.4"
126
+ "xhs-mp-ml-parser": "2.1.6-beta.0"
127
127
  },
128
128
  "scripts": {
129
129
  "version": "formula changelog && git add .",