{"size": 1985, "ext": "js", "max_stars_repo_path": "webpack.config.js", "max_stars_repo_name": "Zielak/noiseTest", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "webpack.config.js", "max_issues_repo_name": "Zielak/noiseTest", "max_issues_repo_issues_event_min_datetime": "2019-10-31T13:26:53.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T23:06:22.000Z", "max_forks_repo_path": "webpack.config.js", "max_forks_repo_name": "Zielak/noiseTest", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 7, "max_forks_count": null, "avg_line_length": 19.4607843137, "max_line_length": 56, "alphanum_fraction": 0.4408060453}
const path = require("path")
const webpack = require("webpack")
const CopyWebpackPlugin = require("copy-webpack-plugin")

const getMode = env => {
  if (env.production) {
    return "production"
  }
  return "development"
}
const getEntries = env => {
  const entry = {
    main: "./src/index.tsx",
    "terrain.worker": "./src/terrain.worker.ts"
  }
  return entry
}
const getPlugins = env => {
  const plugins = []

  if (!env.production) {
    plugins.unshift(
      new webpack.SourceMapDevToolPlugin({
        filename: "[file].map",
        append: "\n//# sourceMappingURL=[url]"
      })
    )
    plugins.push(
      new CopyWebpackPlugin([
        {
          context: "./src",
          from: "*.html",
          to: "./"
        }
      ])
    )
  }

  return plugins
}

module.exports = env => {
  if (env === undefined) {
    env = { development: true }
  }

  const config = {
    entry: getEntries(env),
    output: {
      path: path.join(__dirname, "dist"),
      filename: "[name].js"
    },
    devServer: {
      contentBase: path.join(__dirname, "dist")
    },
    mode: getMode(env),
    module: {
      rules: [
        {
          test: /\.tsx?$/,
          use: "ts-loader",
          exclude: /node_modules/
        },
        {
          test: /\.html$/,
          use: [
            {
              loader: "html-loader",
              options: {
                attrs: ["link:href"]
                // minimize: true,
                // removeComments: true,
                // collapseWhitespace: true
              }
            }
          ]
        },
        {
          test: /\.scss$/,
          use: [
            {
              loader: "style-loader"
            },
            {
              loader: "css-loader"
            },
            {
              loader: "sass-loader"
            }
          ]
        }
      ]
    },
    plugins: getPlugins(env),
    resolve: {
      extensions: [".ts", ".tsx", ".js"]
    }
  }

  return config
}
