const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");

module.exports = {
  entry: "./src/index.ts", // Your entry file
  output: {
    filename: "bundle.js", // Output file
    path: path.resolve(__dirname, "dist"), // Output directory
    clean: true, // Clean output directory before each build
  },
  resolve: {
    extensions: [".ts", ".js", ".html"], // Include .html in resolve extensions
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: "ts-loader", // Use ts-loader for TypeScript files
        exclude: /node_modules/,
      },
      {
        test: /\.html$/,
        use: "html-loader", // Use html-loader for HTML files
      },
    ],
  },
  plugins: [
    new CopyWebpackPlugin({
      patterns: [
        { from: "src/template/**/*.html", to: "template/[name][ext]" }, // Copy HTML files
        { from: "src/template/images/**/*", to: "template/images/[name][ext]" }, // Copy images
      ],
    }),
  ],
};
