[static-build] Patch the gatsby-node config file to invoke @vercel/gatsby-plugin-vercel-builder (#9308)

We need to ensure that `@vercel/gatsby-plugin-vercel-builder` is executed as the very last plugin, which Gatsby itself doesn't really support in the plugins listing. So instead we'll patch the `gatsby-node` file to invoke the plugin in the project's own `onPostBuild()` hook, which does get executed last. The patching is similar to how is done with the `gatsby-config` file.
This commit is contained in:
Nathan Rajlich
2023-01-25 11:07:04 -08:00
committed by GitHub
parent 025344c4a7
commit f18fa8546f
7 changed files with 174 additions and 48 deletions

View File

@@ -1,4 +1,6 @@
module.exports = {
import type { GatsbyConfig } from 'gatsby';
const config: GatsbyConfig = {
siteMetadata: {
title: `Gatsby Default Starter`,
description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
@@ -33,3 +35,5 @@ module.exports = {
},
],
};
export default config;

View File

@@ -1,9 +0,0 @@
exports.createPages = async ({ actions }) => {
const { createPage } = actions;
createPage({
path: '/using-dsg',
component: require.resolve('./src/templates/using-dsg.js'),
context: {},
defer: true,
});
};

View File

@@ -0,0 +1,12 @@
import path from 'path';
import type { GatsbyNode } from 'gatsby';
export const createPages: GatsbyNode['createPages'] = async ({ actions }) => {
const { createPage } = actions;
createPage({
path: '/using-dsg',
component: path.resolve('./src/templates/using-dsg.js'),
context: {},
defer: true,
});
};

View File

@@ -0,0 +1 @@
asset that was added in `onPostBuild`

View File

@@ -1,3 +1,5 @@
const fs = require('fs');
exports.createPages = async ({ actions }) => {
const { createPage } = actions;
createPage({
@@ -8,3 +10,6 @@ exports.createPages = async ({ actions }) => {
});
};
exports.onPostBuild = async () => {
await fs.promises.copyFile('asset.txt', 'public/asset.txt');
};

View File

@@ -21,6 +21,10 @@
{
"path": "/page-data/using-dsg/page-data.json",
"mustContain": "\"componentChunkName\":\"component---src-templates-using-dsg-js\",\"path\":\"/using-dsg\""
},
{
"path": "/asset.txt",
"mustContain": "asset that was added in `onPostBuild`"
}
]
}