const activeEnv = process.env.GATSBY_ACTIVE_ENV || 'development';
const siteMapExcludes = process.env.SITEMAP_EXCLUDE.split(',') || [];
const { getSitemap } = require('./src/helpers/sitemap');

// eslint-disable-next-line import/no-extraneous-dependencies
require('dotenv').config({
  path: `.env.${activeEnv}`,
});

module.exports = {
  flags: {
    DEV_SSR: false,
  },
  plugins: [
    {
      resolve: `gatsby-core-theme`,
      options: {
        siteName: process.env.GATSBY_SITE_NAME,
        preconnectLinks: [process.env.IMAGE_CDN_URL],
      },
    },
    {
      resolve: `gatsby-plugin-sitemap`,
      options: {
        output: `/sitemap.xml`,
        sitemapSize: 5000,
        exclude: siteMapExcludes,
        query: `
        {
          site {
            siteMetadata {
              siteUrl
            }
          }
          allSitePage {
            nodes {
              path
              pageContext
            }
          }
        }
      `,
        serialize: ({ site, allSitePage }) => getSitemap(site, allSitePage),
      },
    },
    `gatsby-plugin-image`,
    `gatsby-plugin-sharp`,
    `gatsby-transformer-sharp`,
  ],
};
