From 184022ed0a8e89033421ba24c5ee85351f880ac8 Mon Sep 17 00:00:00 2001 From: mmeigs Date: Tue, 29 Oct 2024 14:49:51 -0400 Subject: [PATCH] DOP-5111: Disable gatsby-plugin-image on staging (#1296) --- gatsby-config.js | 6 +++--- src/utils/setup/save-asset-files.js | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/gatsby-config.js b/gatsby-config.js index 8672c1e5b..f62fbd952 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -10,9 +10,9 @@ console.log('PATH PREFIX', pathPrefix); // Keep our main plugin at top to include file saving before image plugins const plugins = [ 'gatsby-source-snooty-prod', - `gatsby-plugin-image`, - `gatsby-plugin-sharp`, - `gatsby-transformer-sharp`, // Needed for dynamic images + 'gatsby-plugin-image', + 'gatsby-plugin-sharp', + 'gatsby-transformer-sharp', // Needed for dynamic images { resolve: 'gatsby-source-filesystem', options: { diff --git a/src/utils/setup/save-asset-files.js b/src/utils/setup/save-asset-files.js index 57645a71a..a54ae387c 100644 --- a/src/utils/setup/save-asset-files.js +++ b/src/utils/setup/save-asset-files.js @@ -1,8 +1,11 @@ const fs = require('fs').promises; const path = require('path'); +const { siteMetadata } = require('../site-metadata'); const GATSBY_IMAGE_EXTENSIONS = ['webp', 'png', 'avif']; +const needsImageOptimization = ['dotcomprd', 'dotcomstg'].includes(siteMetadata.snootyEnv); + const saveFile = async (file, data) => { // save files both to "public" and "src/images" directories // the first is for public access, and the second is for image processing @@ -11,6 +14,10 @@ const saveFile = async (file, data) => { }); await fs.writeFile(path.join('public', file), data, 'binary'); + // For staging, skip adding images to src/images dir + // This will functionally skip image optimization, as the plugins source from that dir + if (!needsImageOptimization) return; + const pathList = GATSBY_IMAGE_EXTENSIONS.some((ext) => file.endsWith(ext)) ? ['src', 'images'] : ['public']; await fs.mkdir(path.join(...pathList, path.dirname(file)), { recursive: true,