https://serverless-stack.com/ logo
#help
Title
# help
r

Rafael Sorto

04/05/2022, 5:44 PM
Hello everyone good day! I just have a quick question, do you guys know how to run post build commands on a NextjsSite added to SST ? I normally create a sitemap after the build is done but postbuild doesn't seem to trigger when I'm deploying my site via SST 😞
f

Frank

04/05/2022, 9:23 PM
Hey @Rafael Sorto, is post build a NextJS built-in feature? Or r u just looking to run a command to build the sitemap after Next.js build completes?
r

Rafael Sorto

04/05/2022, 9:25 PM
It's not a NextJS built-in feature. It's like the most common used method to creating a sitemap after the site is built. Once the build command is completed the next-sitemap is called to create the sitemap including every page that was statically created. In this case I think the NestJSSite construct is calling next build directly instead of npm run build
I couldn't find a solution for this 😞 for now I am doing a manual
npm run build
before executing
sst deploy
so the next build happens twice :(
It seems the serverless-next team has an option to execute commands after build, but that option is not directly included in lambda at edge for nextjs
f

Frank

04/05/2022, 9:34 PM
Do u have a link to where it’s talked about for serverless-next?
Copy code
Any commands to run post-build and pre-deploy. For example, you can run any custom code on the .serverless_nextjs directory e.g you can copy additional files into the Lambda: see #767 (comment) for an example for next-18n. Only applies during execution of the serverless command.
I see a reference to build.postBuildCommands in the table of the Inputs
Is there any way to get access to that?
Thank you for taking the time to look into this! I really appreciate it
Do you think it is possible to use that option from SST @Frank?
j

Julien Bras

04/22/2022, 1:25 PM
Hi πŸ‘‹, for reference I have open a case for this same issue here: https://github.com/serverless-stack/serverless-stack/issues/1648 thanks!
r

Rafael Sorto

04/29/2022, 2:45 PM
Thank you! I will look into it to see if maybe our team can provide a PR FOr this
f

Frank

06/10/2022, 9:12 PM
@Rafael Sorto @Julien Bras Added support for this in v1.2.20. You can do something like this:
Copy code
new NextjsSite(stack, "NextSite", {
  path: "path/to/site",
  commandHooks: {
    afterBuild: ["npx next-sitemap"],
  }
});
r

Rafael Sorto

06/10/2022, 9:13 PM
Thank you!!!! This will save a lot of build minutes in our projects !!
2 Views