deploy-static-directory
Quick Answer
Yes! Use the --dir flag to deploy a pre-built static directory:
netlify deploy --dir=./distnetlify deploy --dir=./dist --prod # Deploy directly to productionOverview
Netlify CLI supports deploying static directories without triggering a build. This is useful when:
- You’ve already built your site locally
- Your CI/CD has produced build artifacts
- You want to deploy pre-generated static files
Installation
npm install -g netlify-cliRequirements: Node.js version 20.12.2 or above
Deploy Commands
Draft Deploy (Default)
Deploy to a unique preview URL for testing:
netlify deploy --dir=./buildnetlify deploy --dir=./distnetlify deploy --dir=./outputThis creates a draft deployment with a random alphanumeric subdomain for previewing and testing before going live.
Production Deploy
Skip the draft and deploy directly to your live site:
netlify deploy --dir=./dist --prodThe --prod flag deploys directly to your site’s main URL.
Skip Build Step
If your files are already built, skip the build command:
netlify deploy --dir=./dist --prod --no-buildUse --no-build when:
- Your project has already been built
- You have no build command configured
- You’re deploying pre-generated static files
Configuration Methods
Netlify CLI looks for the publish directory in three places (in order):
1. Command Line Flag (Highest Priority)
netlify deploy --dir=./dist2. Configuration File (netlify.toml)
Create netlify.toml in your project root:
[build] publish = "dist"3. Interactive Prompt
If not specified, Netlify CLI will ask you interactively.
Typical Workflow
# 1. Build your site locallynpm run build
# 2. Deploy to draft URL for testingnetlify deploy --dir=./dist
# 3. Review the draft URL, then deploy to productionnetlify deploy --dir=./dist --prodCI/CD Example (GitHub Actions)
name: Deploy to Netlifyon: push: branches: [main]
jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '20'
- run: npm install - run: npm run build
- name: Deploy to Netlify run: netlify deploy --dir=output --prod env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}Key Concepts
Publish Directory
The directory containing deploy-ready HTML files and assets. Specified relative to the base directory (root by default).
Base Directory
Directory where Netlify checks for dependency files (package.json, .nvmrc), installs dependencies, and runs build commands. Defaults to repository root.
Draft vs Production
- Draft deploys: Unique preview URLs for testing (default behavior)
- Production deploys: Deploys directly to your main site URL (use
--prod)
Common Patterns
Deploy Multiple Directories
For monorepos or multiple sites:
# Deploy different directoriesnetlify deploy --dir=./packages/site-a/dist --prodnetlify deploy --dir=./packages/site-b/dist --prodDeploy with Functions
If you have Netlify Functions:
netlify deploy --dir=./dist --functions=./functions --prodComparison: Netlify vs Cloudflare Pages
| Feature | Netlify CLI | Cloudflare Wrangler |
|---|---|---|
| Deploy command | netlify deploy --dir=./dist | wrangler pages deploy ./dist |
| Draft deploys | --dir (default) | --branch=preview |
| Production | --dir --prod | Default behavior |
| Configuration | netlify.toml | wrangler.toml or flags |
| Skip build | --no-build | Always skips (just uploads) |
Both CLIs support direct static directory uploads!