Turborepo Quickstart
Prerequisites
Make sure you have the following prerequisites in place:
- Monorepo setup: You need a working Turborepo project where you want to integrate a remite cache.
- Turbocache account: If you haven't already done so, sign up for a Turbocache account by following the instructions in our Get Started guide.
Once you have these prerequisites in place, you're ready to start using Turbocache to speed up your builds even further!
Setup
Create a remote cache
After logging into your account, use the create Create Cache button to create a new remote cache. Enter the name of the remote cache to easily identify it later on and choose Turborepo as type of your remote cache.
Purchase a subscription
Go to your newly created remote cache. You will see a message that you need to choose a plan. Click on the Choose a Plan button to purchase a subscription. You will be redirected to our partner Lemon Squeezy.
If you work on the project on a daily basis or with a team of developers we recommend the Pro Subscription. Make sure to enter your VAT Number if you have one. After successfully purchasing a subscription you will be redirected back to your Turbocache dashboard.
Create Turborepo configuration
Now we need to tell turborepo which API to use as remote cache backend.
Create the configuration file .turbo/config.json
it it not already exists and paste the following content
{
"apiurl": "https://turborepo.turbocache.dev",
"teamid": "teamid",
"teamslug": "teamslug"
}
The fields teamid
and teamslug
aren't used at the moment, but they can't be empty.
The important part is to point the apiurl
to our url.
Create and use your API Token
Go to the Settings / API Tokens page of your remote cache and create a new API Token.
Provide a name, so you know where you're using it, e.g. GitHub Actions (CI/CD)
.
Click on show and copy your API Token.
Its important to keep it secret as everybody with the API Token would be able to use your remote cache.
As a last step you need to provide the API Token as cli argument to the turbo
commands where you want to use the remote cache.
Typically the are defined in the scripts
section of the root package.json
file.
We recommend to define the API Token as environment variable to keep the API Token secret.
"scripts": {
"build": "turbo run build --token=\"${TURBOCACHE_API_KEY}\"",
"dev": "turbo run dev --parallel",
"lint": "turbo run lint",
"deploy:staging": "turbo run deploy:staging --token=\"${TURBOCACHE_API_KEY}\"",
"deploy:prod": "turbo run deploy:prod --token=\"${TURBOCACHE_API_KEY}\"",
"format": "prettier --write \"**/*.{ts,tsx,md}\""
},
Ensure to define the environment variable before calling the typical commands:
$ TURBOCACHE_API_KEY=eyJ0eXAi...2NjQ3NTd9 npm run build