const path = require("path");

module.exports = {
  publicPath: "",
  css: {
    sourceMap: process.env.NODE_ENV !== "production"
  },
  configureWebpack: {
    resolve: {
      alias: {
        "@fonts": path.resolve(__dirname, "src/assets/fonts/"),
        "@img": path.resolve(__dirname, "src/assets/img/"),
        "@scss": path.resolve(__dirname, "src/scss/"),
        "@data": path.resolve(__dirname, "src/data/"),
        "@mixins": path.resolve(__dirname, "src/mixins/"),
        "@components": path.resolve(__dirname, "src/components/")
      }
    }
  },
  chainWebpack: config => {
    config.plugin("html").tap(args => {
      const meta = {
        title: "Sebin Nyshkim - Reference Page",
        desc: "The official reference Page for Sebin Nyshkim",
        type: "website",
        url: "https://ref.sebin-nyshkim.net",
        image: "favicon.png",
        twitter: {
          card: "summary",
          creator: "@SebinNyshkim"
        }
      };

      const links = {
        icon: {
          rel: "icon",
          href: meta.image,
          type: "image/png"
        },
        favicon: {
          rel: "favicon",
          href: meta.image,
          type: "image/png"
        }
      };

      args[0].title = meta.title;
      args[0].links = links;
      args[0].meta = {
        "twitter:card": meta.twitter.card,
        "twitter:creator": meta.twitter.creator,
        "twitter:description": meta.desc,
        "twitter:text:title": meta.title,
        "twitter:image": meta.image,
        "og:title": meta.title,
        "og:type": meta.type,
        "og:url": meta.url,
        "og:image": meta.image,
        "og:description": meta.desc
      };

      return args;
    });

    config.module
      .rule("images")
      .test(/\.(png|jpe?g|gif|webp|svg)(\?.*)?$/i)
      .use("image-webpack-loader")
      .loader("image-webpack-loader")
      .tap(options => {
        const newOpts = {
          mozjpeg: {
            progressive: true,
            quality: 75
          },
          pngquant: {
            quality: [0.65, 0.9],
            speed: 4
          },
          gifsicle: {
            interlaced: false
          }
        };
        return { ...options, ...newOpts };
      });
  }
};
