profile
viewpoint

Ask questionsSet `process.env.NETLIFY` to true when running build command

Is your feature request related to a problem? Please describe.

Some frameworks detect when they are being compiled by Netlify to enable Netlify-specific configuration. This can be done by looking for the NETLIFY env var for builds, but this is not set locally, meaning local builds and deploys may miss these.

Describe the solution you'd like

Set NETLIFY to "true" when running build or deploy --build via the cli. It may also be useful to have an additional NETLIFY_LOCAL var.

Describe alternatives you've considered

Setting the value in a build plugin or toml. This is not ideal, as it stops it from being zero-config. Adding it as an env var in framework-info, though this would need to be done for every framework that needed it. Using other ways of detecting that the build is being run via ntl. These are likely to be fragile.

Additional context

The example that inspired this is Nuxt 3, which enables zero-config integrations when it detects the Netlify environment.

netlify/build

Answer questions ascorbic

Ah, in that case if there's a good reason to not set it locally, having a separate local var that can be checked-for might be a good alternative. So if setting NETLIFY has unwanted side-effects, then NETLIFY_LOCAL could be used and if a framework wants to know it can check for both.

useful!

Related questions

No questions were found.
source:https://uonfu.com/
answerer
Matt Kane ascorbic @VelaLabs @netlify UK mk.gg Principal engineer @netlify
Github User Rank List