uni-plugin-light
Version:
uni-app相关插件、loader及webpack基础配置
2 lines (1 loc) • 1.56 kB
JavaScript
;var t=require("path"),e=require("loader-utils"),n=require("fs");function r(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var c=r(t),i=r(n),o="base.scss";var s="ALL";function a(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=(e.getOptions(this)||{}).platforms,r=void 0===n?t:n,c=process.env.UNI_PLATFORM||"";return r===s||r.indexOf(s)>-1||r.includes(c)}var u=["mp-weixin","mp-qq"],f="./css/".concat(o);module.exports=function(t){if(!a.call(this,u))return t;var n=(e.getOptions(this)||{}).topElement,r=void 0===n?"body":n,s=this.context,l=function(t){var e=t.match(/\/([^/]+)$/);return(null==e?void 0:e[1])||""}(s);if(!l)return t;if(t.indexOf(f)<0)return t;var p=function(t){return i.readdirSync(t).filter((function(t){return t.endsWith("scss")&&!t.startsWith(o)})).map((function(t){return t.replace(/\.scss$/,"")}))}(c.join(s,"css"));if(!p.length)return t;var d=new RegExp("src=[\"']".concat(f,"[\"']>[^<]*</style>")),v=function(t){var e=t.styleList,n=t.componentName,r=t.topElement,c=t.dir,i=void 0===c?"":c,o=e.map((function(t){return"\n &--type-".concat(t," {\n @import './").concat(i).concat(t,".scss';\n }")})).join("\n");return"\n".concat(r,".").concat(n," {\n ").concat(o,"\n}\n")}({styleList:p,componentName:l,topElement:r,dir:"css/"});return t.replace(d,">".concat(v,"</style>"))};