Skip to content

Commit

Permalink
DOP-5111: Disable gatsby-plugin-image on staging (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeigs authored Oct 29, 2024
1 parent d4f05a7 commit 184022e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
7 changes: 7 additions & 0 deletions src/utils/setup/save-asset-files.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 184022e

Please sign in to comment.