Zero-config deploys for Netlify Functions

It’s now easier to get started with Netlify Functions because you no longer need to configure a functions directory. Instead you can create a new directory in your site repo with the following path:

SITE_BASE_DIRECTORY/netlify/functions/

Then write your functions in JavaScript or Go inside that directory. As you work, you can run netlify dev to test them locally. Then commit and push to your repo or run netlify deploy to send your updates to Netlify. We’ll automatically package and deploy any functions in the default directory.

What if I want to use a different directory?
You still can! You can configure a custom functions directory in the Netlify UI or in a Netlify configuration file. If you’re already using Netlify Functions in your site, your configured functions directory will still work.

Note that if you set a custom functions directory, Netlify will not try to deploy functions from the default functions directory.

What if I’m using the SITE_BASE_DIRECTORY/netlify/ path for something else?
We recommend you change the name of this directory, as it could cause build failures or other unpredictable issues now or in the future. To prevent issues as a result of this change, we posted an advance notice back in December. We also print a warning message in the deploy logs if we detect the path in your site’s base directory.

What else does zero-config deployment enable?
Glad you asked! :wink: Having a default functions folder makes it possible for Build Plugins to create and deploy functions for a site. We’re using this functionality now in the Next on Netlify plugin, and we’ll be posting a tutorial soon to show you how to do this with your own plugins.

Until then, keep on building! We’ll keep working on helping you build better and faster. :rocket:

4 Likes

Can we combine .netlify and netlify folders?

1 Like

Hi, @web2033. I would not recommend combining the two. They each serve a different purpose and only one of them should be tracked in Git.

The .netlify subdirectory is created in a repository directory by the netlify-cli tool when a repository is linked to a site locally. It is used to store Netlify site specific settings but these are not repo specific settings. They are settings only used on your local system.

It is possible for a single repo to be linked to many sites. For this reason, we usually recommend adding the .netlify subdirectory to .gitignore and to not track that subdirectory. Even if you only link a repo to a single site, the data is only used locally and therefore shouldn’t be in the Git repo. This is similar to reason why you don’t commit node_modules to a repo.

On the other hand, the netlify directory is used for zero-config function deploys. This directory should be part of the repo because it contains source code required for the deployed site.

By comparison, the .netlify directory only is needed on the local system by netlify-cli. It does not contain the any source code required by the deployed site. It is local only data - which is why it doesn’t need to be in the repo itself.

To summarize, the purposes of the .netlify and netlify directories are both specialized and different. Attempting to combine the two is unlikely to provide a benefit and it is not recommended.

1 Like