---
title: 'Build Scripts and Cleanup'
description: 'Use npm-run-all, rimraf, and cross-env to keep Baseline builds clean and predictable for dev and production.'
slug: 'build-scripts-and-cleanup'
type: 'article'
date: 2026-01-25T00:00:00.000Z
lang: 'en'
url: 'https://www.eleventy-baseline.dev/docs/how-to/build-scripts-and-cleanup/'
---

A small set of npm scripts that take Baseline's dev and build commands from "works on my machine" to predictable across platforms. Three helpers do the work: `rimraf` for cleanup, `npm-run-all` for sequencing, and `cross-env` for portable env vars.

---

## Prerequisites

- Baseline installed; `package.json` is ESM (`"type": "module"`).
- `package.json` with `"type": "module"` and scripts (`start`, `build`).
- Install dev dependencies: `npm install rimraf npm-run-all cross-env`.

---

## 1) Install helper packages:

```bash
npm install rimraf npm-run-all cross-env
```

---

## 2) Add scripts to `package.json`.

```json
{
	"scripts": {
		"start": "npm-run-all clean dev",
		"clean": "rimraf dist/",
		"dev": "npx @11ty/eleventy --serve",
		"build:eleventy": "cross-env ELEVENTY_ENV=production npx @11ty/eleventy",
		"build": "npm-run-all clean build:*",
		"dryrun": "npx @11ty/eleventy --dryrun"
	}
}
```

---

## 3) Run local dev with clean output:

```bash
npm start
```

Runs `clean` (removes `dist/`), then the `dev` server.

---

## 4) Run a production build:

```bash
npm run build
```

Runs `clean`, then `build:eleventy` with `ELEVENTY_ENV=production`.

---

## 5) Optional: dry run.

```bash
npm run dryrun
```

Inspect what would be built without writing files.

---

## 6) Gate `noindex` for preview deploys.

Preview and staging environments should not show up in search results. Set a `PREVIEW` (or similar) env flag in those environments and read it from data or computed data to flip `noindex` on. The [[deployment-url-checks | deployment URL checks tutorial]] covers the full URL and env story alongside it.

---

## Notes

- `rimraf dist/` keeps output clean across platforms; adjust the path if you change `dir.output`.
- `npm-run-all` sequences clean → dev/build; keep `clean` first so stale artefacts don't leak into builds.
- `cross-env` sets `ELEVENTY_ENV=production` portably.
