UNPKG

@hap-toolkit/packager

Version:

@hap-toolkit/packager

3 lines (2 loc) 1.73 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.RemoveModulesPlugin=void 0;var _constant=require("../common/constant"),_utils=require("../common/utils");class RemoveModulesPlugin{constructor(e){this.options=e}apply(e){e.hooks.compilation.tap("RemoveModulesPlugin",(e=>{e.hooks.optimizeModules.tap("RemoveModulesPlugin",(e=>{e.forEach((e=>{const{_source:t,request:s}=e;if(this.isNewJsCardAndCardcomp(s)){const{_valueAsString:n,_valueAsBuffer:o}=t||{},u=n||(null==o?void 0:o.toString())||"";this.getRequestType(s)===_constant.LOADER_PATH_UX.type&&"string"==typeof u&&this.updateUXDependency(e)}}))})),e.hooks.optimizeChunks.tap("RemoveModulesPlugin",(t=>{t.forEach((t=>{const s=e.chunkGraph;s.getChunkModules(t).forEach((e=>{const{request:n}=e;if(this.isNewJsCardAndCardcomp(n)){const o=this.getRequestType(n);!_constant.LOADER_INFO_LIST.map((e=>e.type)).includes(o)||o!==_constant.LOADER_PATH_TEMPLATE.type&&o!==_constant.LOADER_PATH_STYLE.type||s.disconnectChunkAndModule(t,e)}}))}))}))}))}getRequestType(e){const t=e.replace(/\\/g,"/"),s=(0,_utils.getLastLoaderPath)(t);let n="";if(s){const e=_constant.LOADER_INFO_LIST.find((e=>e.path===s));n=e&&e.type||""}return n}updateUXDependency(e){e.dependencies.filter((e=>{const t=e.request,s=this.getRequestType(t);return s===_constant.LOADER_PATH_TEMPLATE.type||s===_constant.LOADER_PATH_STYLE.type})).forEach((t=>{e.removeDependency(t)}))}isNewJsCardAndCardcomp(e){if(e&&e.lastIndexOf("?")>0){const t=e.lastIndexOf("?"),s=e.substring(t+1).split("&");return s&&s.indexOf("newJSCard=1")>=0&&(s.indexOf("uxType=card")>=0||s.indexOf("uxType=comp")>=0)}return!1}}exports.RemoveModulesPlugin=RemoveModulesPlugin; //# sourceMappingURL=remove-modules-plugin.js.map