// vite.config.js
import { defineConfig } from "file:///home/litruv/Development/cinny-desktop/cinny/node_modules/vite/dist/node/index.js";
import react from "file:///home/litruv/Development/cinny-desktop/cinny/node_modules/@vitejs/plugin-react/dist/index.mjs";
import { wasm } from "file:///home/litruv/Development/cinny-desktop/cinny/node_modules/@rollup/plugin-wasm/dist/es/index.js";
import { viteStaticCopy } from "file:///home/litruv/Development/cinny-desktop/cinny/node_modules/vite-plugin-static-copy/dist/index.js";
import { vanillaExtractPlugin } from "file:///home/litruv/Development/cinny-desktop/cinny/node_modules/@vanilla-extract/vite-plugin/dist/vanilla-extract-vite-plugin.cjs.js";
import { NodeGlobalsPolyfillPlugin } from "file:///home/litruv/Development/cinny-desktop/cinny/node_modules/@esbuild-plugins/node-globals-polyfill/dist/index.js";
import inject from "file:///home/litruv/Development/cinny-desktop/cinny/node_modules/@rollup/plugin-inject/dist/es/index.js";
import topLevelAwait from "file:///home/litruv/Development/cinny-desktop/cinny/node_modules/vite-plugin-top-level-await/exports/import.mjs";
import { VitePWA } from "file:///home/litruv/Development/cinny-desktop/cinny/node_modules/vite-plugin-pwa/dist/index.js";
import fs from "fs";
import path from "path";

// build.config.ts
var build_config_default = {
  base: "/"
};

// vite.config.js
var copyFiles = {
  targets: [
    {
      src: "node_modules/pdfjs-dist/build/pdf.worker.min.mjs",
      dest: "",
      rename: "pdf.worker.min.js"
    },
    {
      src: "node_modules/gif.js/dist/gif.worker.js",
      dest: ""
    },
    {
      src: "netlify.toml",
      dest: ""
    },
    {
      src: "config.json",
      dest: ""
    },
    {
      src: "public/manifest.json",
      dest: ""
    },
    {
      src: "public/res/android",
      dest: "public/"
    },
    {
      src: "public/locales",
      dest: "public/"
    }
  ]
};
function serverMatrixSdkCryptoWasm(wasmFilePath) {
  return {
    name: "vite-plugin-serve-matrix-sdk-crypto-wasm",
    configureServer(server) {
      server.middlewares.use((req, res, next) => {
        if (req.url === wasmFilePath) {
          const resolvedPath = path.join(path.resolve(), "/node_modules/@matrix-org/matrix-sdk-crypto-wasm/pkg/matrix_sdk_crypto_wasm_bg.wasm");
          if (fs.existsSync(resolvedPath)) {
            res.setHeader("Content-Type", "application/wasm");
            res.setHeader("Cache-Control", "no-cache");
            const fileStream = fs.createReadStream(resolvedPath);
            fileStream.pipe(res);
          } else {
            res.writeHead(404);
            res.end("File not found");
          }
        } else {
          next();
        }
      });
    }
  };
}
function serveGifWorker() {
  return {
    name: "vite-plugin-serve-gif-worker",
    configureServer(server) {
      server.middlewares.use((req, res, next) => {
        if (req.url === "/gif.worker.js") {
          const resolvedPath = path.join(path.resolve(), "/node_modules/gif.js/dist/gif.worker.js");
          if (fs.existsSync(resolvedPath)) {
            res.setHeader("Content-Type", "application/javascript");
            res.setHeader("Cache-Control", "no-cache");
            const fileStream = fs.createReadStream(resolvedPath);
            fileStream.pipe(res);
          } else {
            res.writeHead(404);
            res.end("File not found");
          }
        } else {
          next();
        }
      });
    }
  };
}
var vite_config_default = defineConfig({
  appType: "spa",
  publicDir: false,
  base: build_config_default.base,
  server: {
    port: 8080,
    host: "0.0.0.0",
    fs: {
      // Allow serving files from one level up to the project root
      allow: [".."]
    }
  },
  plugins: [
    serverMatrixSdkCryptoWasm("/node_modules/.vite/deps/pkg/matrix_sdk_crypto_wasm_bg.wasm"),
    serveGifWorker(),
    topLevelAwait({
      // The export name of top-level await promise for each chunk module
      promiseExportName: "__tla",
      // The function to generate import names of top-level await promise in each chunk module
      promiseImportName: (i) => `__tla_${i}`
    }),
    viteStaticCopy(copyFiles),
    vanillaExtractPlugin(),
    wasm(),
    react(),
    VitePWA({
      srcDir: "src",
      filename: "sw.ts",
      strategies: "injectManifest",
      injectRegister: false,
      manifest: false,
      injectManifest: {
        injectionPoint: void 0
      },
      devOptions: {
        enabled: false,
        type: "module"
      }
    })
  ],
  optimizeDeps: {
    esbuildOptions: {
      define: {
        global: "globalThis"
      },
      plugins: [
        // Enable esbuild polyfill plugins
        NodeGlobalsPolyfillPlugin({
          process: false,
          buffer: true
        })
      ]
    }
  },
  build: {
    outDir: "dist",
    sourcemap: true,
    copyPublicDir: false,
    rollupOptions: {
      plugins: [inject({ Buffer: ["buffer", "Buffer"] })]
    }
  }
});
export {
  vite_config_default as default
};
//# sourceMappingURL=data:application/json;base64,[encoded data, 10316 characters]
