Refactor gatsby-config.js for improved configuration#7601
Conversation
Updated site metadata and plugin configurations for Gatsby setup. Removed unused code and adjusted feed settings for better performance. Signed-off-by: Lee Calcote <lee.calcote@layer5.io>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Refactors gatsby-config.js by simplifying build profile logic, revising plugin configuration, and expanding RSS feed definitions.
Changes:
- Removed previous “lite build” collection-exclusion logic and added a new blog-only dev profile driven by env vars.
- Reworked RSS feed setup with multiple feeds + updated GraphQL queries/serialization.
- Restructured filesystem sourcing to explicitly list collections and adjusted several plugin/flag settings.
| serialize: ({ query: { site, allPosts } }) => { | ||
| return allPosts.nodes.map((node) => { | ||
| return Object.assign({}, node.frontmatter, { | ||
| title: node.frontmatter.title, | ||
| author: node.frontmatter.author, | ||
| description: node.frontmatter.description, | ||
| date: node.frontmatter.date, | ||
| url: site.siteMetadata.siteUrl + node.fields.slug, | ||
| guid: site.siteMetadata.siteUrl + node.fields.slug, | ||
| enclosure: node.frontmatter.thumbnail && { | ||
| url: | ||
| site.siteMetadata.siteUrl + | ||
| node.frontmatter.thumbnail.publicURL, | ||
| }, | ||
| custom_elements: [{ "content:encoded": node.html }], | ||
| }); | ||
| }); | ||
| }, | ||
| query: `{ | ||
| allPosts: allMdx( | ||
| sort: {frontmatter: {date: DESC}} | ||
| filter: {fields: {collection: {in: ["blog", "resources", "news"]}}, frontmatter: {published: {eq: true}, category: {nin: ["Programs", "Community", "Events", "FAQ"]}}} | ||
| limit: 20 | ||
| ) { | ||
| nodes { | ||
| body |
There was a problem hiding this comment.
The feed serializer uses node.html, but the query only selects body (and MDX nodes typically don’t expose an html field). This will likely produce empty/undefined content:encoded in the RSS output. Fix by either selecting the correct field that exists on your MDX nodes for RSS content (and using that consistently), or changing custom_elements to use the queried field (body/excerpt) and ensuring it’s in the desired format for RSS readers.
| site.siteMetadata.siteUrl + | ||
| node.frontmatter.thumbnail.publicURL, | ||
| }, | ||
| custom_elements: [{ "content:encoded": node.html }], |
There was a problem hiding this comment.
This feed mixes description: node.body with content:encoded: node.html, but node.html is not queried (and may not exist for MDX). Unify on a single, valid field for both description and content:encoded (and make sure the GraphQL query selects that field). As-is, content:encoded is likely undefined.
| custom_elements: [{ "content:encoded": node.html }], | |
| custom_elements: [{ "content:encoded": node.body }], |
| overrides: { | ||
| // or disable plugins | ||
| inlineStyles: false, | ||
| cleanupIds: false, |
There was a problem hiding this comment.
The previous config explicitly disabled SVGO’s removeViewBox which prevents responsive SVGs from breaking. With that override removed, preset-default may strip viewBox again, which can break scaling/responsiveness of icons/logos. Re-add an override to keep viewBox (e.g., removeViewBox: false) if the site relies on responsive SVG sizing.
| cleanupIds: false, | |
| cleanupIds: false, | |
| removeViewBox: false, |
| { | ||
| resolve: "gatsby-plugin-webpack-bundle-analyser-v2", | ||
| options: { | ||
| disable: true, |
There was a problem hiding this comment.
The bundle analyzer plugin is now always present but permanently disabled, which makes it unusable even when you want to analyze a build. Recommend wiring disable to an env flag (e.g., disabled unless process.env.ANALYZE_BUNDLE is set) or restoring the prior conditional plugin inclusion so the analyzer can be enabled on-demand without modifying config.
| disable: true, | |
| disable: !process.env.ANALYZE_BUNDLE, |
| resolve: "gatsby-plugin-styled-components", | ||
| options: { | ||
| minify: true, | ||
| minify: false, |
There was a problem hiding this comment.
Disabling styled-components minification can increase JS/CSS payload size in production and negatively impact Core Web Vitals. If this is intended only for development/debugging, consider toggling minify based on environment (e.g., enabled in production).
| minify: false, | |
| minify: process.env.NODE_ENV === "production", |
| "gatsby-plugin-sharp", | ||
| "gatsby-transformer-sharp", |
There was a problem hiding this comment.
gatsby-plugin-sharp / gatsby-transformer-sharp are included here as string plugins, but later in the file they’re also added again with explicit options. Including the same plugin twice can lead to duplicate work and confusing/undefined option precedence. Keep only the configured instances (or only the string entries), but not both.
| "gatsby-plugin-sharp", | |
| "gatsby-transformer-sharp", |
| name: "collections", | ||
| ignore: collectionIgnoreGlobs, | ||
| name: "images", | ||
| path: `${__dirname}/src/assets/images`, |
There was a problem hiding this comment.
The prior images filesystem source had an ignore list to avoid ingesting heavy/unneeded directories and file types (notably **/*.svg and several large subtrees). Removing those ignores can significantly increase node creation time and memory usage during builds. Consider restoring the previous ignore patterns (or an equivalent scoped set) to keep sourcing performant.
| path: `${__dirname}/src/assets/images`, | |
| path: `${__dirname}/src/assets/images`, | |
| ignore: ["**/*.svg"], |
| { | ||
| resolve: "gatsby-plugin-purgecss", | ||
| options: { | ||
| printRejected: true, | ||
| } | ||
| }, |
There was a problem hiding this comment.
gatsby-plugin-purgecss is now always enabled (it was previously production-only). Running PurgeCSS during development commonly causes confusing styling issues with dynamic class names and slows dev builds. Consider restricting it to production builds (or using a config that disables it in development) to avoid dev-time regressions.
| { | |
| resolve: "gatsby-plugin-purgecss", | |
| options: { | |
| printRejected: true, | |
| } | |
| }, | |
| ...(process.env.NODE_ENV === "production" | |
| ? [ | |
| { | |
| resolve: "gatsby-plugin-purgecss", | |
| options: { | |
| printRejected: true, | |
| }, | |
| }, | |
| ] | |
| : []), |
Updated site metadata and plugin configurations for Gatsby setup. Removed unused code and adjusted feed settings for better performance.
Description
This PR fixes #
Notes for Reviewers
Signed commits