const path = require("path")
const yaml = require("js-yaml")
const fs = require("fs")

const FaviconsWebpackPlugin = require("favicons-webpack-plugin")
const CopyPlugin = require("copy-webpack-plugin")

let config
try {
  config = yaml.load(fs.readFileSync(path.join(__dirname, "config.yml"), "utf8"))
} catch (e) {
  console.log(e)
}

module.exports = {
  entry: [path.resolve("src", "dummy.js")],
  output: {
    filename: "../build/dummy.js",
    path: path.join(__dirname, "static"),
    publicPath: "/",
    clean: true
  },
  plugins: [
    new CopyPlugin({
      patterns: [
        {
          from: "**/*",
          context: path.resolve(__dirname, "src", "static")
        }
      ]
    }),

    new FaviconsWebpackPlugin({
      logo: path.resolve("src", "static", "favicon", "favicon.svg"),
      cache: true,
      prefix: "favicon/",
      inject: false,
      favicons: {
        appName: config.title,
        appShortName: config.title.concat(" - ", config.params.subtitle),
        appDescription: config.params.description,
        background: "#2f333e",
        theme_color: "#2f333e",
        icons: {
          android: { offset: 10 },
          appleIcon: { offset: 10 },
          appleStartup: { offset: 10 },
          favicons: true,
          windows: { offset: 10 },
          yandex: false,
          coast: false
        }
      }
    })
  ]
}
