Skip to main content
RapidDev - Software Development Agency
replit-tutorial

How to customize build scripts in Replit

Customize build scripts in Replit by configuring the [deployment] build command in your .replit file. You can chain multiple steps — install dependencies, run tests, compile TypeScript, bundle assets — using shell syntax. The onBoot command runs when the Repl first starts, and the run command handles development execution. Together, these three settings give you full control over your build pipeline.

What you'll learn

  • Configure the run, onBoot, and [deployment] build commands in the .replit file
  • Chain multiple build steps using shell syntax (&&, ||, ;)
  • Set up TypeScript compilation, asset bundling, and test execution in the build pipeline
  • Handle build failures gracefully with error checking and fallback commands
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Beginner8 min read15-20 minutesAll Replit plans (Starter, Core, Pro). Deployment builds require Autoscale or Reserved VM deployments.March 2026RapidDev Engineering Team
TL;DR

Customize build scripts in Replit by configuring the [deployment] build command in your .replit file. You can chain multiple steps — install dependencies, run tests, compile TypeScript, bundle assets — using shell syntax. The onBoot command runs when the Repl first starts, and the run command handles development execution. Together, these three settings give you full control over your build pipeline.

Configure Multi-Step Build Scripts for Complex Replit Projects

Simple projects can get by with a one-line run command, but complex projects need multi-step builds — installing dependencies, compiling TypeScript, running tests, bundling assets, and generating files. This tutorial shows you how to configure the .replit file to handle all of these steps using the run command (development), the onBoot command (startup), and the [deployment] build command (production). You will learn to chain commands, handle errors, and structure your build pipeline for reliability.

Prerequisites

  • A Replit account on any plan
  • A Replit App with code that requires a build step (TypeScript, React, etc.)
  • Basic familiarity with the Replit Shell and .replit file
  • Understanding of what build steps your project needs (install, compile, test, etc.)

Step-by-step guide

1

Understand the three command types in .replit

The .replit file supports three different command hooks, each serving a different purpose. The 'run' command executes when you press the Run button during development. The 'onBoot' command runs once when the Repl first starts (ideal for installing dependencies). The '[deployment] build' command runs before each deployment to prepare your app for production. Understanding which hook to use for each task is the key to a reliable build pipeline. Open .replit (enable 'Show hidden files' in the file tree menu) to see and edit these values.

typescript
1# .replit file three command hooks
2
3# Runs once when the Repl first starts
4onBoot = "npm install"
5
6# Runs every time you press the Run button
7run = "node index.js"
8
9# Runs before each deployment
10[deployment]
11build = ["sh", "-c", "npm install && npm run build"]
12run = ["sh", "-c", "node dist/index.js"]

Expected result: You understand the purpose of each command hook and can identify which one to use for each build step.

2

Configure a multi-step development run command

For development, you often need to compile code before running it. Update the run command to chain multiple steps using the double-ampersand (&&) operator, which stops execution if any step fails. This ensures that if compilation fails, the app does not start with stale code. You can also run multiple processes in parallel using the single ampersand (&) for cases like running a frontend dev server alongside a backend API.

typescript
1# Sequential build steps (stops on first failure)
2run = "npm run build && node dist/index.js"
3
4# Parallel processes (frontend + backend)
5run = "cd client && npm run dev & cd server && node index.js & wait"
6
7# TypeScript compilation then run
8run = "npx tsc --noEmit && npx ts-node index.ts"

Expected result: Pressing the Run button executes your build steps in order. If any step fails, the Console shows the error and subsequent steps do not run.

3

Set up the onBoot command for dependency installation

The onBoot command runs once when the Repl first starts or restarts. This is the ideal place for dependency installation since it only needs to happen once, not on every Run press. Common use cases include npm install, pip install -r requirements.txt, or any other setup command that should only run at startup. This reduces the delay when pressing Run repeatedly during development.

typescript
1# Install dependencies on boot
2onBoot = "npm install"
3
4# Multiple boot steps
5onBoot = "npm install && npx prisma generate"
6
7# Python equivalent
8onBoot = "pip install -r requirements.txt"

Expected result: Dependencies are installed automatically when the Repl starts. You do not need to manually run npm install after opening the project.

4

Configure the deployment build command

The [deployment] build command runs in a clean environment before each deployment. This is where you install dependencies, compile TypeScript, bundle assets, run tests, and prepare your production-ready code. The build command must be self-contained — assume nothing is pre-installed. Chain all necessary steps with && so the deployment fails early if any step encounters an error. This prevents broken code from reaching production.

typescript
1[deployment]
2build = ["sh", "-c", "npm ci && npm test && npm run build"]
3run = ["sh", "-c", "NODE_ENV=production node dist/index.js"]
4deploymentTarget = "cloudrun"

Expected result: Deployments install dependencies, run tests, and build the project. If any step fails, the deployment is aborted and error details appear in the deployment logs.

5

Add environment-specific configuration

Your build scripts may need different behavior in development versus production. Use the [run.env] section in .replit to set environment variables for the development run command. For deployment, set environment variables in the Deployments pane under Settings. You can also check the REPLIT_DEPLOYMENT variable in your code — it is set to '1' in deployed environments and undefined in development.

typescript
1# .replit file with environment variables
2run = "node index.js"
3
4[run.env]
5NODE_ENV = "development"
6DEBUG = "app:*"
7PORT = "3000"
8
9[deployment]
10build = ["sh", "-c", "npm ci && npm run build"]
11run = ["sh", "-c", "NODE_ENV=production node dist/index.js"]
12deploymentTarget = "cloudrun"

Expected result: Development and production environments use different settings. Your app can check process.env.NODE_ENV or process.env.REPLIT_DEPLOYMENT to adjust behavior.

6

Create a build script in package.json for complex pipelines

For builds with many steps, keep the .replit run command simple and put the complexity in package.json scripts. This makes each step individually testable from Shell and keeps the .replit file clean. Create separate scripts for each phase — clean, compile, test, build — and a single combined script that runs them all in order.

typescript
1{
2 "scripts": {
3 "clean": "rm -rf dist",
4 "compile": "tsc",
5 "test": "jest --passWithNoTests",
6 "build": "npm run clean && npm run compile && npm run test",
7 "start": "node dist/index.js",
8 "dev": "npx ts-node index.ts"
9 }
10}

Expected result: Each build phase can be run independently from Shell. The combined build script runs all phases in order. The .replit file calls 'npm run build' for a clean interface.

Complete working example

.replit
1# .replit complete build configuration for a TypeScript project
2
3entrypoint = "src/index.ts"
4modules = ["nodejs-20:v8-20230920-bd784b9"]
5
6# Install dependencies when the Repl first starts
7onBoot = "npm install"
8
9# Development: compile and run with ts-node
10run = "npx ts-node src/index.ts"
11
12# Development environment variables
13[run.env]
14NODE_ENV = "development"
15PORT = "3000"
16DEBUG = "app:*"
17
18[nix]
19channel = "stable-24_05"
20
21# Production deployment configuration
22[deployment]
23# Build: install deps, run tests, compile TypeScript, bundle
24build = ["sh", "-c", "npm ci && npm test && npm run build"]
25# Run: start the compiled JavaScript output
26run = ["sh", "-c", "NODE_ENV=production node dist/index.js"]
27deploymentTarget = "cloudrun"
28
29# Port configuration
30[[ports]]
31localPort = 3000
32externalPort = 80
33
34# Hide build artifacts and config from the file tree
35hidden = [".config", "package-lock.json", "node_modules", "dist", "coverage"]

Common mistakes when customizing build scripts in Replit

Why it's a problem: Confusing the top-level run command (development) with the [deployment] run command (production)

How to avoid: The top-level 'run' executes when you press Run during development. The [deployment] 'run' executes in production. They can and often should be different commands.

Why it's a problem: Not running npm install in the deployment build step, causing missing dependency errors

How to avoid: The deployment environment is clean. Always include 'npm ci' or 'npm install' as the first step in your [deployment] build command.

Why it's a problem: Using a single ampersand (&) when you need sequential execution (&&)

How to avoid: Single & runs commands in parallel (background). Double && runs sequentially and stops on failure. Use && for build pipelines where order and success matter.

Why it's a problem: Forgetting to add secrets to the deployment pane after setting them in workspace Secrets

How to avoid: Workspace secrets do not carry to deployments automatically. Open the Deployments pane, go to Settings, and add each required secret separately.

Why it's a problem: Not hiding build artifacts in the .replit file, cluttering the file tree with dist/ and coverage/ directories

How to avoid: Add build output directories to the hidden array: hidden = ["dist", "coverage", "node_modules", ".config"].

Best practices

  • Use onBoot for dependency installation so it only runs once at startup, not on every Run press
  • Chain build steps with && so the pipeline stops on the first failure instead of continuing with broken code
  • Use 'npm ci' instead of 'npm install' in deployment builds for faster, deterministic installations
  • Keep the .replit run command simple and put complex build logic in package.json scripts
  • Always set NODE_ENV=production in the [deployment] run command for proper production behavior
  • Add deployment secrets separately in the Deployments pane — workspace secrets do not carry over automatically
  • Hide build output directories (dist, build, coverage) in the .replit hidden array to keep the file tree clean
  • Test each build step individually from Shell before chaining them together

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

I have a TypeScript project in Replit that needs a multi-step build: install dependencies, compile TypeScript, run tests, and start the production server. How do I configure the .replit file with onBoot, run, and [deployment] build commands?

Replit Prompt

Configure the build pipeline for this TypeScript project. Set up onBoot to install dependencies. Set the run command to compile and run with ts-node for development. Configure the [deployment] build command to run npm ci, npm test, and npm run build in sequence. Set the deployment run command to start the compiled output with NODE_ENV=production.

Frequently asked questions

The top-level 'run' command executes when you press the Run button during development. The [deployment] build command runs once before each deployment to prepare production code. The [deployment] run command starts your app in production.

The onBoot command runs once when the Repl first starts or restarts. It does not run again when you press the Run button. It is ideal for one-time setup tasks like installing dependencies.

Yes. Chain commands with && for sequential execution (stops on first failure) or & for parallel execution. For example: run = "npm run build && node dist/index.js".

The deployment build environment starts clean. You must include 'npm ci' or 'npm install' in your [deployment] build command before any step that requires dependencies.

Yes. Prompt Agent v4: 'Configure a multi-step build pipeline. Set onBoot to install dependencies. Set the run command for TypeScript development. Configure deployment build to run tests and compile.' Agent will update the .replit file and package.json.

Check the deployment logs in the Deployments pane (Logs tab). The logs show output from each build step, including error messages. You can also test each step individually by running them in Shell.

Use npm ci for deployment builds. It installs exact versions from package-lock.json, is faster than npm install, and provides more reliable, deterministic builds for production.

For complex pipelines with conditional steps, caching, or multi-environment builds, connect to GitHub and use GitHub Actions for CI/CD. The RapidDev team can help design professional build and deployment pipelines for complex projects.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.