Netlify config
About Netlify's config file
Just push your main branch from your machine or edit on GitHub and a Netlify build will run using your config settings.
If you want more control than setting values in the Netlify UI, create a config file in your repo.
Resources
- Configure in my Netlify recipes, for samples for various tools like Jekyll and React.
- File-based Configuration in the Netlify docs.
File
netlify.toml
It should be at the root of the repo.
It is a TOML file. Indentation should be two spaces.
Fields
The minimum config two params under [build]
as below.
command
- what shell command to run to build the app (dependencies are already installed when this runs).publish
- which output directory to serve as a site. This directory is usually unversioned in git, for static site generators.
Environment
If you have environment variables that are sensitive, put them directly in Netlify, under Build & Deploy then Environment.
If they are safe to be visible in GitHub, add them like this, based on the docs.
- Prod only.
[context.production] environment = { FOO = "bar", NODE_VERSION = "14.15.3" }
Here setting in Production and Deploy Preview, since it is not enough to set it in only Production when I tested on a deploy preview.
[context.production]
environment = { RUBY_VERSION = "2.7.0" }
[context.deploy-preview]
environment = { RUBY_VERSION = "2.7.0" }
For sensitive environment variables, you might have to make an environment permission choice under Sensitive variable policy - see docs.
Functions
Choose a directory to load serveless functions and background functions from.
Defaults to netlify/functions
if not set.
Override example using functions
directory at the root instead:
[build]
functions = "functions"
I think the endpoint will be fixed.
/netlify/functions/my-api