// @ts-check
const { isProduction, isTurbo } = require("./config");

let webpackConfig = {
  mode: isProduction ? "production" : "development",
  bail: isProduction ? true : false,
  // devServer: require("./webpack/devServer")(),
  // experiments: {
  //   asset: true
  // },
  // @see https://webpack.js.org/configuration/devtool/
  devtool: isTurbo
    ? false
    : isProduction
    ? false // "source-map"
    : "eval-cheap-source-map",
  entry: require("./webpack/entry")(),
  output: require("./webpack/output"),
  optimization: require("./webpack/optimization"),
  resolve: require("./webpack/resolve"),
  stats: {
    assets: false,
    hash: false,
    timings: false,
    chunkModules: false,
    modules: false,
    cached: false,
    cachedAssets: false,
    version: false,
    builtAt: false,
    entrypoints: false,
    excludeAssets: /.*LICENSE\.txt$/, // Exclude license files
    // chunks: false,
    // reasons: false,
    // source: false,
    // errorDetails: false,
    // excludeAssets: /.*\.(?!js$|css$)/, // show only css and js files
    // children: false, // hide scripts.blade.php partial info
  },
  module: {
    rules: [
      require("./webpack/rules-scripts")(),
      ...require("./webpack/rules-styles")(),
      require("./webpack/rules-fonts")(),
      require("./webpack/rules-images")(),
      require("./webpack/rules-media")(),
      // {
      //   test: /\.(woff2?|ttf|otf|eot|svg)$/,
      //   type: "asset",
      //   generator: {
      //     filename: "fonts/[hash][ext]"
      //   }
      // },
      // {
      //   test: /\.(gif|png|jpe?g|svg)$/i,
      //   type: "asset",
      //   generator: {
      //     filename: "images/[hash][ext]"
      //   }
      // },
      // {
      //   test: /\.(mp4|mp3|ogg|wav)$/i,
      //   type: "asset",
      //   generator: {
      //     filename: "media/[ext]"
      //   }
      // }
    ],
  },
  plugins: require("./webpack/plugins")(),
};

if (process.env.DEV_ANALYZE === "true") {
  const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
  const smp = new SpeedMeasurePlugin();
  webpackConfig = smp.wrap(webpackConfig);
}

module.exports = webpackConfig;
