UNPKG

plugin-light

Version:

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

2 lines (1 loc) 4.84 kB
"use strict";function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function t(t){return function(t){if(Array.isArray(t))return e(t)}(t)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||function(t,r){if(t){if("string"==typeof t)return e(t,r);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(t,r):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(!e)return;if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(e,t)}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var i=0,o=function(){};return{s:o,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,c=!0,l=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return c=e.done,e},e:function(e){l=!0,a=e},f:function(){try{c||null==r.return||r.return()}finally{if(l)throw a}}}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var i=require("@babel/parser"),o=require("@babel/traverse"),a=require("@babel/generator"),c=require("htmlparser2"),l=require("dom-serializer").default;module.exports=function(e){if("h5"===process.env.VUE_APP_PLATFORM)return e;var n,s,u=function(e){var n=e.indexOf("<template"),i=e.lastIndexOf("</template>"),o=e.slice(n+9+1,i),a=c.parseDocument(o,{lowerCaseTags:!1,lowerCaseAttributeNames:!1});function s(e,n){var i,o=[],a=r(e.children);try{for(a.s();!(i=a.n()).done;){var c=i.value;c.name==n&&o.push(c),c.children&&o.push.apply(o,t(s(c,n)))}}catch(e){a.e(e)}finally{a.f()}return o}function u(e,t,r){var n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];Object.keys(e).includes(t)&&(e[r]=e[t]),n&&Object.keys(e).includes(":".concat(t))&&u(e,":".concat(t),":".concat(r),!1)}var d=s(a,"Swipe");if(d.push.apply(d,t(s(a,"van-swipe"))),null===d||0===d.length)return"<template>\n".concat(o,"\n</template>\n");var f,p=["SwipeItem","van-swipe-item"],m=r(d);try{for(m.s();!(f=m.n()).done;){var v=f.value;v.name="swiper",null==v.attribs[":indicator-dots"]&&(v.attribs["indicator-dots"]=v.attribs["indicator-dots"]||"true"),null==v.attribs[":indicator-active-color"]&&(v.attribs["indicator-active-color"]=v.attribs["indicator-color"]||"#1989fa"),null==v.attribs[":indicator-color"]&&(v.attribs["indicator-color"]=v.attribs["indicator-inactive-color"]||"rgba(0, 0, 0, .3)");var y,b=r(v.children);try{for(b.s();!(y=b.n()).done;){var h=y.value;p.includes(h.name)&&(h.name="swiper-item")}}catch(e){b.e(e)}finally{b.f()}for(var w=0,g=["autoplay",":autoplay"];w<g.length;w++){var S=g[w];Object.keys(v.attribs).includes(S)&&(v.attribs[S]=String(parseInt(v.attribs[S])>0))}u(v.attribs,"loop","circular"),u(v.attribs,"show-indicators","indicator-dots")}}catch(e){m.e(e)}finally{m.f()}var I=l(a,{decodeEntities:!1});return"<template>\n".concat(I,"\n</template>\n")}(e),d=function(e){var t=/<script(.)*?>/,r=e.match(t);if(!r)return"<script><\/script>";var n=r.index+r[0].length,c=e.lastIndexOf("<\/script>"),l=e.slice(n,c),s=i.parse(l,{sourceType:"module"}),u={ImportSpecifier:function(e){"Swipe"!==e.node.imported.name&&"SwipeItem"!==e.node.imported.name||e.remove()},ImportDefaultSpecifier:function(e){"Swipe"!==e.node.local.name&&"SwipeItem"!==e.node.local.name||e.remove()},ImportDeclaration:function(e){0!==e.node.specifiers.length||"vant/lib/swipe/index.css"!==e.node.source.value&&"vant/lib/swipe-item/index.css"!==e.node.source.value||e.remove()},ExpressionStatement:function(e){var t,r,n;(null===(t=e.node.expression.arguments)||void 0===t?void 0:t.length)>0&&("Swipe"===(null===(r=e.node.expression.arguments[0])||void 0===r?void 0:r.name)||"SwipeItem"===(null===(n=e.node.expression.arguments[0])||void 0===n?void 0:n.name))&&e.remove()},Property:function(e){"Swipe"!==e.node.key.name&&"SwipeItem"!==e.node.key.name||e.remove()}};o.default(s,u);var d=a.default(s,{});return"".concat(r[0],"\n").concat(d.code,"\n<\/script>\n")}(e),f=(s=(n=e).indexOf("<style"),n.slice(s));return"".concat(u,"\n").concat(d,"\n").concat(f,"\n")};