Hello everyone good day! I just have a quick quest...
# help
r
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
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
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
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
Hi πŸ‘‹, for reference I have open a case for this same issue here: https://github.com/serverless-stack/serverless-stack/issues/1648 thanks!
r
Thank you! I will look into it to see if maybe our team can provide a PR FOr this
f
@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
Thank you!!!! This will save a lot of build minutes in our projects !!