# CLI

> sitelo dev, build, preview, and common flags.

The `sitelo` CLI wraps the bundled Vite and auto-injects the HTML pages plugin.

## Commands

`shell`

```bash
sitelo              # same as sitelo dev
sitelo dev          # development server
sitelo build        # production build
sitelo preview      # preview the production build
sitelo lighthouse   # audit the production build
```

- `dev` — real SSR renders on request, including dynamic routes, plus a small dev toolbar
- `build` — static HTML in `dist/` (or your `outDir`)
- `preview` — serve the production build locally
- `lighthouse` — audit the production build (needs the `lighthouse` peer dependency)

Disable the toolbar with `devToolbar: false` in `sitelo.config.js` — see [Configuration](https://sitelo.dev/docs/configuration).

## Useful flags

`shell`

```bash
sitelo --port 8888
sitelo build --outDir public --emptyOutDir
sitelo --root docs
```

- `--port` / `--host` / `--open` — server
- `--outDir` / `--emptyOutDir` / `--base` — build
- `--root` — project root (handy for a `docs/` site)
- `--config` — custom Vite config file
- `--mode` / `--logLevel` / `--debug`

Prefer Vite options in `sitelo.config.js` under `vite` for anything you reuse across commands.

## Finding unused code

[knip](https://knip.dev) finds files, exports and dependencies nothing uses. On a sitelo project it needs one hint: pages and islands are discovered from the filesystem, so nothing imports them, and without being told otherwise knip reports the whole site as unused files.

`shell`

```bash
npm install -D knip
```

`knip.js`

```javascript
import { knipConfig } from 'sitelo/knip'

export default knipConfig()
```

`shell`

```bash
npx knip
```

`knipConfig()` reads your `sitelo.config.js` and marks the pages and islands as entry points the same way the build discovers them — `pagesDir`, `pageExtensions`, `include` and `exclude` all apply. What is left in the report is code the site genuinely never reaches.

One thing it cannot see: a client script a page references by URL rather than import, like `<script src="/js/app.js">`. List those yourself, and pass anything else knip accepts alongside — it is spread into the result. The trailing `!` is knip’s marker for production code, which is what a script shipped to the browser is.

`knip.js`

```javascript
export default knipConfig({
  entry: ['src/js/app.js!'], // what the pages load with a <script src>
  ignore: ['legacy/**'], // and anything else knip accepts
})
```
