2 lines
4.3 KiB
JavaScript

(function(n,s){typeof exports=="object"&&typeof module!="undefined"?module.exports=s(require("code-inspector-core"),require("path")):typeof define=="function"&&define.amd?define(["code-inspector-core","path"],s):(n=typeof globalThis!="undefined"?globalThis:n||self,n.WebpackCodeInspectorPlugin=s(n.codeInspectorCore,n.path))})(this,function(n,s){"use strict";var E=Object.defineProperty,R=Object.defineProperties;var U=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var q=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var W=(n,s,r)=>s in n?E(n,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[s]=r,j=(n,s)=>{for(var r in s||(s={}))q.call(s,r)&&W(n,r,s[r]);if(T)for(var r of T(s))z.call(s,r)&&W(n,r,s[r]);return n},k=(n,s)=>R(n,U(s));var g=(n,s,r)=>new Promise((P,v)=>{var h=a=>{try{A(r.next(a))}catch(b){v(b)}},x=a=>{try{A(r.throw(a))}catch(b){v(b)}},A=a=>a.done?P(a.value):Promise.resolve(a.value).then(h,x);A((r=r.apply(n,s)).next())});function r(t,e){return g(this,null,function*(){if(!t||!e)return[];const o=typeof t=="function"?yield t():t;let i=[];if(typeof o=="object"&&!Array.isArray(o))for(const c in o){const u=o[c],f=u.import||u;P(i,f,e)}else P(i,o,e);return i.filter(c=>!!c)})}function P(t,e,o){typeof e=="string"?t.push(v(e,o)):Array.isArray(e)&&t.push(...e.map(i=>v(i,o)))}function v(t,e){return s.isAbsolute(t)?n.normalizePath(t):t.startsWith(".")?s.resolve(e,n.normalizePath(t)):""}let h="";typeof __dirname!="undefined"?h=__dirname:h=s.dirname(n.fileURLToPath(typeof document=="undefined"&&typeof location=="undefined"?require("url").pathToFileURL(__filename).href:typeof document=="undefined"?location.href:document.currentScript&&document.currentScript.src||new URL("index.umd.js",document.baseURI).href));let x=!0;const A=(t,e)=>{var l,d,y;if(!x)return;x=!1;const o=(e==null?void 0:e.compiler)||e,i=(l=o==null?void 0:o.options)==null?void 0:l.module,c=(i==null?void 0:i.rules)||(i==null?void 0:i.loaders)||[];let u=t.include||[];Array.isArray(u)||(u=[u]);let f=t.exclude||[];Array.isArray(f)||(f=[f]),c.push(j({test:(d=t.match)!=null?d:/\.(vue|jsx|tsx|js|ts|mjs|mts)$/,exclude:[...f,/node_modules/],use:[{loader:s.resolve(h,"./loader.js"),options:t}]},t.enforcePre===!1?{}:{enforce:"pre"}),j({test:(y=t.match)!=null?y:/\.html$/,resourceQuery:/vue/,use:[{loader:s.resolve(h,"./loader.js"),options:t}]},t.enforcePre===!1?{}:{enforce:"pre"}),...u.map(p=>j({resource:{and:[p,/\.(vue|jsx|tsx|js|ts|mjs|mts)$/]},use:[{loader:s.resolve(h,"./loader.js"),options:t}]},t.enforcePre===!1?{}:{enforce:"pre"})),k(j({},t.injectTo?{resource:t.injectTo}:{test:/\.(jsx|tsx|js|ts|mjs|mts)$/,exclude:/node_modules/}),{use:[{loader:s.resolve(h,"./inject-loader.js"),options:t}],enforce:"post"}))};function a(t,e){return n.getCodeWithWebComponent({options:k(j({},t),{importClient:"code"}),file:"main.js",code:"",record:e,inject:!0})}function b(i){return g(this,arguments,function*({options:t,record:e,assets:o}){const c=Object.keys(o).filter(u=>/\.html$/.test(u));if(c.length){const u=yield a(t,e);c.forEach(f=>{var d,y;const l=(y=(d=o[f])==null?void 0:d.source)==null?void 0:y.call(d);if(typeof l=="string"){const p=l.replace("<head>",'<head><script type="module">\n'.concat(u,"\n<\/script>"));o[f]={source:()=>p,size:()=>p.length}}})}})}class C{constructor(e){this.options=e}apply(e){return g(this,null,function*(){var i,c,u,f,l,d,y,p,w;if(x=!0,this.options.close||!n.isDev(this.options.dev,((i=e==null?void 0:e.options)==null?void 0:i.mode)==="development"||process.env.NODE_ENV==="development"))return;const o={port:0,entry:"",output:this.options.output,inputs:r((c=e==null?void 0:e.options)==null?void 0:c.entry,(u=e==null?void 0:e.options)==null?void 0:u.context)};if(((l=(f=e==null?void 0:e.options)==null?void 0:f.cache)==null?void 0:l.type)==="filesystem"&&(this.options.cache?a(this.options,o):e.options.cache.version="code-inspector-".concat(Date.now())),((p=(y=(d=e==null?void 0:e.options)==null?void 0:d.experiments)==null?void 0:y.cache)==null?void 0:p.type)==="persistent"&&(this.options.cache?a(this.options,o):e.options.experiments.cache.version="code-inspector-".concat(Date.now())),A(k(j({},this.options),{record:o}),e),(w=e==null?void 0:e.hooks)!=null&&w.emit){const D=this.options;e.hooks.emit.tapAsync("WebpackCodeInspectorPlugin",(_,L)=>g(this,null,function*(){let $={};_.getAssets?$=yield _.getAssets():$=_.assets,yield b({options:D,record:o,assets:$}),L()}))}})}}return C});