(function(e,u){typeof exports=="object"&&typeof module<"u"?module.exports=u(require("vite"),require("glob"),require("fs"),require("path"),require("rollup-plugin-copy")):typeof define=="function"&&define.amd?define(["vite","glob","fs","path","rollup-plugin-copy"],u):(e=typeof globalThis<"u"?globalThis:e||self,e.VitePluginMp=u(e.vite,e.glob,e.fs,e.path,e.RollupPluginCopy))})(this,function(e,u,f,t,m){"use strict";function D(o){if(!o||!o.buildDir||!o.outputDir)throw new Error("Required options cannot be empty");const n={buildDir:e.normalizePath(o.buildDir),outputDir:e.normalizePath(o.outputDir)},h=["apis","components","constants","pages","tools"].concat(o.processedDir??[]),l=["assets"].concat(o.processedAssetDir??[]),a=u.globSync([`${n.buildDir}/{${h.join(",")}}/**/*.{json,wxml,scss,ts}`,`${n.buildDir}/{app,config,sitemap}.{json,wxml,scss,ts}`,`${t.dirname(n.buildDir)}/project.config.json`,`${t.dirname(n.buildDir)}/project.private.config.json`]).map(r=>{const i=e.normalizePath(r);return r.endsWith(".json")||r.endsWith(".wxml")?i+"?raw":i});return[{name:"vite-plugin-mp",config(){return{build:{cssCodeSplit:!1,rollupOptions:{input:a,output:{dir:n.outputDir,assetFileNames(r){return r.name==="style.css"&&r.source!=="/* vite internal call, ignore */"?e.normalizePath(t.join(t.basename(n.buildDir),"app.wxss")):"assets/[name]-[hash][extname]"},entryFileNames(r){const i=r.facadeModuleId??"";if(a.includes(i)){let s;return i.endsWith(".ts")?s=i.replace(n.buildDir,t.basename(n.buildDir)):s=i.replace("?raw","").replace(n.buildDir,t.basename(n.buildDir)).replace(t.dirname(n.buildDir),""),s.endsWith(".ts")?s=s.replace(".ts",".js"):s.endsWith(".scss")&&(s=s.replace(".scss",".wxss")),s.startsWith("/")?s.substring(1):s}return"[name].js"}}}}}},async transform(r,i){if(a.includes(i))return i.endsWith("?raw")?"internal":{code:r,map:null}},async generateBundle(r,i){const s=[];for(const c in i){const p=i[c];if(p.type==="chunk"){const d=p.facadeModuleId??"";if(a.includes(d)&&!d.endsWith(".ts")){const b=d.replace("?raw","");if(d.endsWith("app.scss")){s.push(c);continue}p.code=f.readFileSync(b,"utf8")}}}s.forEach(c=>delete i[c])}},{name:"vite-plugin-mp-assets",async buildStart(){const r=l.length===1?l[0]:`{${l.join(",")}}`,i=u.globSync([`${n.buildDir}/${r}/**/*`]);for(const s of i)this.addWatchFile(e.normalizePath(s))}},{...m({hook:"closeBundle",targets:l.map(r=>({src:e.normalizePath(t.join(n.buildDir,r)),dest:e.normalizePath(t.join(n.outputDir,t.basename(n.buildDir)))}))})}]}return D});