TL;DR: Is it possible to set a deploy command in my netlify.toml based on a build hook?
I’m trying to run a different command when building the site from my build hook then from building the site from merging a PR. I’ve thought about setting a build command base on the trigger_title but ran in the problem of not being able to run any logic (if/else) commands in my netlify.toml.
The reason I want to try this is because of the new release from Nuxt where they included separate build commands for restarting webpack and generating the routes. So when my build hook comes from my CMS I only want to re-generate the routes.
If anybody has a solution or a different kind of workable approach to this that would be great
Someone told me of a way to maybe make it work:
You have to deploy trough Github Actions to Netlify and in that script, you’ll set the command: yarn build && yarn export. Now in Netlify, you should set the default deploy command to nuxt deploy. If it’s correct when changing functionality and merging to your master branch it should completely rebuild and when making content changes trough the CMS it should fire only: yarn export.
Haven’t tested this myself but sounds like something that could work, think you’ll have to turn off auto-deploys.
A little if statement should then help you to distinguish between a hook build and a non-hook build, allowing you to run different commands per context.
If my understanding is correct, the Nuxt build is not cached between deployment? So only running running “nuxt export” wouldn’t work. I haven’t tried it myself, but since this Netlify build plugin exists for Nuxt, I guess that by default Netlify doesn’t cache the webpack build.
Haha, you did take a thorough look! I’ve just seen your pull request on that repo .
Caching is a funny old game. You can read up on how and what we cache but that’s not the be-all-and-end-all. Plugins like the one listed will tailor what’s cached for your SSG.
haha
And upon closer inspection of the code, it makes use of the hook-specific variables you recommended
Thanks for the link about the way Netlify handles cache.
You could put it in your root directory and call it from your build command: sh ./build.sh. I don’t have a specific example however, how about something like…
if [ INCOMING_HOOK_URL == "url" ]
then
#do this for this web hook
else
#do this
fi
I got the shell script to run fine now, although i ran into another problem … which is kinda logical - that he cant run export if he does not have any build files.
10:36:31 AM: [fatal] No build files found in /opt/build/repo/.nuxt/dist/client.
10:36:31 AM: Please run nuxt build --target static before calling nuxt export
Is it somehow possible to cache the /opt/build/repo/ contents on netllify till the next time you do a full Application rebuild ?
Ooooh. Good question. I’m not clued up with Nuxt specifically however there’s a few modules on npm which may help?
You may be able to add a command to your nuxt export command such as cp /files /dist && nuxt export. Maybe the module above will help preserve the data. Otherwise, it’ll need some engineering!
Hey there!
I’ve just installed the nuxt-netlify-cache plugin and I can report that it works like a charm! Build times triggered by a hook were cut down from 65 seconds to 41 seconds!