text: "use strict";
  
  const CopyWebpackPlugin = require("copy-webpack-plugin");
  const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  const PATHS = require("./paths");
  const glob = require("glob");
  
  const { merge } = require("webpack-merge");
  
  
  // To re-use webpack configuration across templates,
  // CLI maintains a common webpack configuration file - `webpack.common.js`.
  // Whenever user creates an extension, CLI adds `webpack.common.js` file
  // in template's `config` folder
  const common = {
    output: {
      // the build folder to output bundles and assets in.
      path: PATHS.build,
      // the filename template for entry chunks
      filename: "[name].js",
    },
    devtool: "source-map",
    stats: {
      all: false,
      errors: true,
      builtAt: true,
    },
    module: {
      rules: [
        // Help webpack in understanding CSS files imported in .js files
        {
          test: /\.ts$/,
          use: "ts-loader",
        },
        {
          test: /\.css$/,
          use: [MiniCssExtractPlugin.loader, "css-loader"],
        },
        {
          test: /\.scss$/,
          use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
        },
        // Check for images imported in .js files and
        {
          test: /\.(png|jpe?g|gif)$/i,
          use: [
            {
              loader: "file-loader",
              options: {
                outputPath: "images",
                name: "[name].[ext]",
              },
            },
          ],
        },
      ],
    },
    resolve: {
      extensions: [
        ".ts", ".js",
      ],
      fallback: {
        "path": require.resolve("path-browserify")
      }
    },
    plugins: [
      // Copy static assets from `public` folder to `build` folder
      new CopyWebpackPlugin({
        patterns: [
          {
            from: "**/*",
            context: "public",
          },
        ]
      }),
      // Extract CSS into separate files
      new MiniCssExtractPlugin({
        filename: "[name].css",
      }),
    ],
  };
  
  // Merge webpack configuration files
  const entry = glob.sync(PATHS.src + "/*.{js,ts,scss}").map(v => {
    return [v.match(".+/(.+?).[a-z]+([?#;].*)?$")[1], v];
  });
  const entryObj = Object.fromEntries(entry);
  console.log(entryObj);
  
  const config = merge(common, { entry: entryObj, });
  
  module.exports = config;
  