Edge Functions: Custom build command confusion

Hey,

I’ve got a build generation script (CLI) which builds code into JS in the format of an Edge Function - on the Create an Edge Functions integration | Netlify Docs docs, it mentions you can output a function into netlify/edge-functions. This part is working.

I’ve added a custom build command:

[dev]
  command = "custom_cli build --dev"

It seems Netlify starts, runs my command and then stops as the command stopped with an exit code. I’d like my command to create the edge function, and then let the usual netlify dev server take over as normal.

Is there anyway to run my build script before netlify dev starts?

EDIT: What I’m trying to say is:

Can I write to .netlify/edge-functions before netlify dev kicks off, rather than after, so I don’t have to start my own server?

@Ehesp I might be misunderstanding, but if you want to execute something before netlify dev, could you not just do this by running it before ever calling netlify dev?

E.g. custom_cli build --dev && netlify dev

Although that works, I was hoping that I could move the responsibility of running the custom CLI away from the user, so they just use netlify dev as normal and things “just work”.

You could add a script to your package.json that runs that command. So, your users can then use npm run dev:custom

It’s a bit of a weird one - I don’t have a package.json. It’s another language compiling to JavaScript, hence why I was hoping for netlify dev to compile the language to JS (in the format an edge function expects), then let netlify run those functions.

Right now, it looks for the generated functions (which doesn’t exist), then compiles.

I’ve also noticed that the netlify dev command doesn’t detect file changes when another process has written to a file… but that’s probably one for GitHub issues.

Ah okay, I don’t believe that would be currently possible. Netlify CLI scans and tries to load the functions almost at the start of its process, so I don’t believe there would be any other way to achieve what you need. You can file an issue on the CLI repo as a feature request.

Sure - made one here: Allow dev command to run script before executing · Issue #5438 · netlify/cli · GitHub