Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[general/netlify integration] nitro dev should delete build artifacts generated by previous nitro build #1970

Open
1 task done
Skn0tt opened this issue Nov 30, 2023 · 1 comment

Comments

@Skn0tt
Copy link

Skn0tt commented Nov 30, 2023

Describe the feature

I'll start with a specific problem, and then generalise to what the broader gap is in my view.

Given a Nitro-powered project, when running netlify build and then netlify dev, the Netlify Dev environment will pick up build artifacts like .netlify/functions-internal/server and dist/_redirect and run them as part of the dev environment. This breaks the dev environment, because those artifacts are from an old build. What should be happening instead is that the Netlify Dev environment proxies all requests to the Nitro Dev server.

There's multiple ways to fix this. One possible fix within Nitro would be to clear all artifacts generated during build on startup of the Nitro Dev server. We could also look at working around this on the Netlify Dev side, although this would probably be workaround that's specific to Nitro - which is always brittle.


The broader gap, in my view, is that Nitro presets only concern themselves with a hosting provider's deployment step (build output etc), but not with the development step.

In the code, you can see this in the fact that the dev server will alway run the nitro-dev preset: https://github.com/unjs/nitro/blob/48c79556b8588d392adfde35faf5c040e2465cf1/src/cli/commands/dev.ts#L37

My idea for how to fix this is to run provider detection in the dev server, and to use that second preset to call hooks specific to local dev. To fix the specific problem i'm reporting, an onPreDev hook could be added to the Netlify preset, which clears any existing build artifacts.

Additional information

  • Would you be willing to help implement this feature? Yes!
@Skn0tt Skn0tt changed the title [netlify integration] nitro dev should delete build artifacts generated by previous nitro build [general/netlify integration] nitro dev should delete build artifacts generated by previous nitro build Nov 30, 2023
@pi0
Copy link
Member

pi0 commented Nov 30, 2023

Thanks for the nice writeup issue. Supporting presets in dev mode is in the plan. In the meantime, you can simply add a rm -rf to the netlify dev command i guess as a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants