Skip to content

Commit 45c6731

Browse files
authored
Merge pull request #7229 from layer5io/leecalcote/chore/full-site
Chore: Build performance - DSG for development environment and SSR for production environment
2 parents 2b62849 + a4093c3 commit 45c6731

4 files changed

Lines changed: 31 additions & 4 deletions

File tree

.env.development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
GATSBY_GRAPHQL_IDE=playground
1+
# GATSBY_GRAPHQL_IDE=playground

gatsby-config.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
/* eslint-env node */
22

3+
const isDevelopment = process.env.NODE_ENV === "development";
34
const isProduction = process.env.NODE_ENV === "production";
45
const isFullSiteBuild = process.env.BUILD_FULL_SITE === "true";
56
const HEAVY_COLLECTIONS = ["members", "integrations"];
67
const collectionIgnoreGlobs = isFullSiteBuild
78
? []
89
: HEAVY_COLLECTIONS.map((name) => `**/${name}/**`);
9-
// const isDevelopment = process.env.NODE_ENV === "development";
10+
const devFlags = isDevelopment
11+
? {
12+
PARALLEL_SOURCING: false,
13+
PRESERVE_FILE_DOWNLOAD_CACHE: true,
14+
PRESERVE_WEBPACK_CACHE: true,
15+
}
16+
: {};
1017

1118
module.exports = {
1219
siteMetadata: {
@@ -21,8 +28,8 @@ module.exports = {
2128
},
2229
flags: {
2330
FAST_DEV: true,
24-
PARALLEL_SOURCING: false, // Disable parallel sourcing to reduce memory pressure
2531
DEV_SSR: false,
32+
...devFlags,
2633
},
2734
trailingSlash: "never",
2835
plugins: [
@@ -518,4 +525,4 @@ module.exports = {
518525
"gatsby-plugin-meta-redirect",
519526
// make sure this is always the last one
520527
],
521-
};
528+
};

gatsby-node.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const slugify = require("./src/utils/slugify");
1111
const { paginate } = require("gatsby-awesome-pagination");
1212
const { createFilePath } = require("gatsby-source-filesystem");
1313
const config = require("./gatsby-config");
14+
const isDevelopment = process.env.NODE_ENV === "development";
15+
const isProduction = process.env.NODE_ENV === "production";
1416
const {
1517
componentsData,
1618
} = require("./src/sections/Projects/Sistent/components/content");
@@ -92,6 +94,12 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
9294

9395
const envCreatePage = (props) => {
9496
const pageConfig = { ...props };
97+
98+
if (isDevelopment) {
99+
pageConfig.defer = true;
100+
} else if (isProduction) {
101+
pageConfig.mode = "SSR";
102+
}
95103
pageConfig.slices = { ...DEFAULT_SLICES, ...(pageConfig.slices || {}) };
96104

97105
if (process.env.CI === "true") {

src/sections/Learn-Layer5/Chapters/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ const Chapters = ({ chapterData, courseData, location, serviceMeshesList, TOCDat
7070
const findServiceMeshImage = (images, serviceMesh) => images.find(image => image.name.toLowerCase() == serviceMesh);
7171
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
7272

73+
const missingServiceMeshImages = availableServiceMeshesArray
74+
.filter(({ section }) => {
75+
const meshImage = findServiceMeshImage(serviceMeshImages, section);
76+
return !(meshImage && meshImage.imagepath?.childImageSharp?.gatsbyImageData);
77+
})
78+
.map(({ section }) => section);
79+
80+
if (missingServiceMeshImages.length > 0) {
81+
const context = chapterData?.fields?.slug || "unknown-chapter";
82+
throw new Error(`[Chapters] Missing meshesYouLearn image data for: ${missingServiceMeshImages.join(", ")} (chapter: ${context}).`);
83+
}
84+
7385
const ServiceMeshesAvailable = ({ serviceMeshes }) => serviceMeshes.map((sm, index) => {
7486
const meshImage = findServiceMeshImage(serviceMeshImages, sm.section);
7587

0 commit comments

Comments
 (0)