.slugignore File
Background
When you deploy an application, our build system fetches all the required dependencies according to the programming language and the requirements of your project. For compiled languages, their executable or package is then built. All these files are gathered in an application image. This image is stored and distributed to our servers when they need to run your application. So one consequence is: the lighter the faster.
Definition
The .slugignore
file allows you to list files and directories that should not
be included in the image after the build of your application. When you have heavy
build dependencies, you often don’t need them after the build, so why keep them?
They would only slow down your application’s boot time.
Usage
Create a .slugignore
file at the root of your project containing on each line
the name of a file or directory you want to exclude from your image.
Examples
Ruby Application
Your Ruby application doesn’t need to have all its test suites when running
in production, so the spec
folder can be filtered out:
.slugignore
content:
spec
Rails Application
Most Rails applications also use Webpacker to bundle the assets. If this is your case, you can safely remove the following folders that are not necessary to run the application:
doc
/tmp/cache
/node_modules
/.cache/yarn
PHP Application
Some PHP applications also use Webpack (or Webpack Encore) to bundle the assets. If this is your case, you can safely remove the following folders that are not necessary to run the application:
doc
/tmp/cache
/node_modules
/.cache/yarn
Java Application
Your application build process result in a .war
file and you don’t want to keep all the generated
classes and jar archives from the build:
.slugignore
content:
.m2
Go Application
You’re deploying a Go application but you don’t want to keep the Godeps directory containing all the third party dependency source code in the image:
.slugignore
content:
Godeps