{"version":3,"file":"plugins.mjs","sources":["../../../../src/node/vite/plugins.ts"],"sourcesContent":["import type { Plugin } from 'vite';\n\nimport { getDocumentHTML } from '../staticFiles';\nimport type { BuildContext } from '../create-build-context';\n\nconst buildFilesPlugin = (ctx: BuildContext): Plugin => {\n  const CHUNK_ID = '.strapi/client/app.js';\n\n  return {\n    name: 'strapi/server/build-files',\n    apply: 'build',\n    buildStart() {\n      this.emitFile({\n        type: 'chunk',\n        id: CHUNK_ID,\n        name: 'strapi',\n      });\n    },\n    async generateBundle(_options, outputBundle) {\n      const bundle = outputBundle;\n      const entryFile = Object.values(bundle).find(\n        (file) =>\n          file.type === 'chunk' && file.name === 'strapi' && file.facadeModuleId?.endsWith(CHUNK_ID)\n      );\n\n      if (!entryFile) {\n        throw new Error(`Failed to find entry file in bundle (${CHUNK_ID})`);\n      }\n\n      if (entryFile.type !== 'chunk') {\n        throw new Error('Entry file is not a chunk');\n      }\n\n      const entryFileName = entryFile.fileName;\n      const entryPath = [ctx.basePath.replace(/\\/+$/, ''), entryFileName].join('/');\n\n      this.emitFile({\n        type: 'asset',\n        fileName: 'index.html',\n        source: getDocumentHTML({\n          logger: ctx.logger,\n          props: {\n            entryPath,\n          },\n        }),\n      });\n    },\n  };\n};\n\nexport { buildFilesPlugin };\n"],"names":["buildFilesPlugin","ctx","CHUNK_ID","name","apply","buildStart","emitFile","type","id","generateBundle","_options","outputBundle","bundle","entryFile","Object","values","find","file","facadeModuleId","endsWith","Error","entryFileName","fileName","entryPath","basePath","replace","join","source","getDocumentHTML","logger","props"],"mappings":";;AAKA,MAAMA,mBAAmB,CAACC,GAAAA,GAAAA;AACxB,IAAA,MAAMC,QAAAA,GAAW,uBAAA;IAEjB,OAAO;QACLC,IAAAA,EAAM,2BAAA;QACNC,KAAAA,EAAO,OAAA;AACPC,QAAAA,UAAAA,CAAAA,GAAAA;YACE,IAAI,CAACC,QAAQ,CAAC;gBACZC,IAAAA,EAAM,OAAA;gBACNC,EAAAA,EAAIN,Q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