// craco.config.js
const path = require("path");
require("dotenv").config();

module.exports = {
  webpack: {
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
    configure: (webpackConfig) => {
      // Prevent build from failing on warnings
      webpackConfig.stats = {
        warnings: false,
      };
      return webpackConfig;
    },
  },
  devServer: {
    port: 5300,
    open: false,
    historyApiFallback: true,
    hot: true,
    client: {
      overlay: {
        errors: true,
        warnings: false,
      },
      webSocketURL: {
        port: 443,
      },
    },
    setupMiddlewares: (middlewares, devServer) => {
      return middlewares;
    },
    onListening: function (devServer) {
      if (!devServer) {
        throw new Error("webpack-dev-server is not defined");
      }
      const port = devServer.server.address().port;
      console.log("Frontend listening on port:", port);
    },
  },
};
