mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-10 12:57:47 +00:00
[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:
@@ -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;
|
||||
@@ -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,
|
||||
});
|
||||
};
|
||||
12
packages/static-build/test/fixtures/gatsby-v4-pnpm/gatsby-node.ts
vendored
Normal file
12
packages/static-build/test/fixtures/gatsby-v4-pnpm/gatsby-node.ts
vendored
Normal 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,
|
||||
});
|
||||
};
|
||||
1
packages/static-build/test/fixtures/gatsby-v4/asset.txt
vendored
Normal file
1
packages/static-build/test/fixtures/gatsby-v4/asset.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
asset that was added in `onPostBuild`
|
||||
@@ -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');
|
||||
};
|
||||
|
||||
@@ -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`"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user