UNPKG

plugin-light

Version:

Webpack 相关插件、Loader、基础配置及 CLI 命令

2 lines (1 loc) 1.81 kB
"use strict";var e=require("t-comm"),r=require("loader-utils");function t(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}require("fs");var n=t(require("path"));function l(e){return n.relative(process.cwd(),n.resolve(e))}var o="LOADER_LOGS";function i(e,r){global[o]||(global[o]={}),global[o][e]||(global[o][e]=[]),global[o][e].push(r)}var a="mp-weixin",c="mp-qq",s={MP_WX:".wxss",MP_QQ:".qss",MP_ALIPAY:".acss",MP_JD:".jxss"};Object.keys(s).reduce((function(e,r){return e[r]=s[r].slice(1),e}),{});var u="ALL";function f(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=(r.getOptions(this)||{}).platforms,n=void 0===t?e:t,l=process.env.UNI_PLATFORM||"";return n===u||n.indexOf(u)>-1||n.includes(l)}var p=[a,c];module.exports=function(t){if(e.replaceAllPolyfill(),!f.call(this,p))return t;var n=r.getOptions(this)||{},o=n.replaceLibraryList,a=void 0===o?[]:o,c=n.replaceContentList,s=void 0===c?[]:c;if(!(null!=a&&a.length||s.length))return t;for(var u=this.resourcePath,v=0;v<s.length;v++){var g=s[v],h=g.path,b=g.content,d=void 0===b?"":b,O="function"==typeof d?d():d;if(u.match(new RegExp(h)))return i("replace-library.result.json",{file:l(u),type:"CONTENT",path:h}),O}for(var m=t,y=function(){var e=a[L],r=e.from,t=e.to;if(e.exact)m=m.replaceAll("'".concat(r,"'"),"'".concat(t,"'"));else{var n=new RegExp("(?<=import(?:[\\s\\S]+from)?\\s+)(?:'|\")(".concat(r,"[\\w\\/\\-\\.]*)(?:'|\")"));n.test(m)&&(m=m.replaceAll(n,(function(){return"'".concat(t,"'")})),i("replace-library.result.json",{file:l(u),type:"LIBRARY",from:r,to:t}))}},L=0;L<a.length;L++)y();return m};