Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions src/content/docs/workers/ci-cd/builds/automatic-prs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
pcx_content_type: concept
title: Automatic pull requests
description: Learn about the pull requests Workers Builds creates to configure your project or resolve issues.
sidebar:
order: 3
---

Workers Builds can automatically create pull requests in your repository to configure your project or resolve deployment issues. This page explains the different types of PRs you may receive and how to handle them.

## Configuration PR

When you connect a repository that does not have a Wrangler configuration file, Workers Builds runs `wrangler deploy` which triggers [automatic project configuration](/workers/framework-guides/automatic-configuration/). Instead of failing, it creates a pull request with the necessary configuration for your detected framework.

:::note
A configuration PR is only created when your deploy command is `npx wrangler deploy`. If you have a custom deploy command, autoconfig will still run and configure your project, but no PR will be created.
:::

### Why you should merge the PR

Without the configuration in your repository, every build has to run autoconfig first, which means your project gets built twice - once during autoconfig to generate the configuration, and again for the actual deployment. Merging the PR commits the configuration to your repository, so future builds skip autoconfig and go straight to building and deploying. This results in faster deployments and version-controlled settings.

### What the PR includes

![Example of an automatic configuration pull request created by Workers Builds](~/assets/images/workers/ci-cd/builds/automatic-pr.png)

The configuration PR may contain changes to the following files, depending on your framework:

- **`wrangler.jsonc`** - Wrangler configuration file with your Worker settings
- **Framework adapter** - Any required Cloudflare adapter for your framework (for example, `@astrojs/cloudflare` for Astro)
- **Framework configuration** - Updates to framework config files (for example, `astro.config.mjs` for Astro or `svelte.config.js` for SvelteKit)
- **`package.json`** - New scripts like `deploy`, `preview`, and `cf-typegen`, plus required dependencies
- **`package-lock.json`** / **`yarn.lock`** / **`pnpm-lock.yaml`** - Updated lock file with new dependencies
- **`.gitignore`** - Entries for `.wrangler` and `.dev.vars*` files
- **`.assetsignore`** - For frameworks that generate worker files in the output directory

### PR description

The PR description includes:

- **Detected settings** - Framework, build command, deploy command, and version command
- **Preview link** - A working preview generated using the detected settings
- **Next steps** - Links to documentation for adding bindings, custom domains, and more

:::note
When you merge the PR, Workers Builds will update your build and deploy commands if they do not match the detected settings, ensuring successful deployments.
:::

## Name conflict PR

If Workers Builds detects a mismatch between your Worker name in the Cloudflare dashboard and the `name` field in your Wrangler configuration file, it will create a pull request to fix the conflict.

This can happen when:
- You rename your Worker in the dashboard but not in your config file
- You connect a repository that was previously used with a different Worker
- The `name` field in your config does not match the connected Worker

The PR will update the `name` field in your Wrangler configuration to match the Worker name in the dashboard.

For more details, refer to the [name conflict changelog](/changelog/2025-02-20-builds-name-conflict/).

## Reviewing PRs

When you receive a PR from Workers Builds:

1. **Review the changes** - Check that the configuration matches your project requirements
2. **Test the preview** - Use the preview link in the PR description to verify everything works
3. **Merge when ready** - Once satisfied, merge the PR to enable faster deployments
13 changes: 13 additions & 0 deletions src/content/docs/workers/ci-cd/builds/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@

When connecting your Git repository to your Worker, you can customize the configurations needed to build and deploy your Worker.

## How Workers Builds works

When a commit is pushed to your connected repository, Workers Builds runs a two-step process:

1. **Build command** _(optional)_ - Compiles your project (for example, `npm run build` for frameworks like Next.js or Astro)
2. **Deploy command** - Deploys your Worker to Cloudflare (defaults to `npx wrangler deploy`)

For preview builds (commits to branches other than your production branch), the deploy command is replaced with a **preview deploy command** (defaults to `npx wrangler versions upload`), which creates a preview version without promoting it to production.

## Build settings

Build settings can be found by navigating to **Settings** > **Build** within your Worker.
Expand Down Expand Up @@ -60,9 +69,13 @@
| `yarn exec wrangler versions upload` | You can customize the package manager used to run Wrangler. |
| `npx wrangler versions upload --env staging` | If you have a [Wrangler environment](/workers/ci-cd/builds/advanced-setups/#wrangler-environments) Worker, you should set your non-production branch deploy command with the environment flag. For more details, see [Advanced Setups](/workers/ci-cd/builds/advanced-setups/#wrangler-environments). |

### Automatic configuration for new projects

If your repository does not have a Wrangler configuration file, the deploy command (`wrangler deploy`) will trigger [automatic project configuration](/workers/framework-guides/automatic-configuration/). This detects your framework, creates the necessary configuration, and opens a [pull request](/workers/ci-cd/builds/automatic-prs/) for you to review. Once you merge the PR, your project is configured and future builds will deploy normally.

### API token

The API token in Workers Builds defines the access granted to Workers Builds for interacting with your account's resources. Currently, only user tokens are supported, with account-owned token support coming soon.

Check warning on line 78 in src/content/docs/workers/ci-cd/builds/configuration.mdx

View workflow job for this annotation

GitHub Actions / Semgrep

semgrep.style-guide-coming-soon

Found forbidden string 'coming soon'. Too often we set expectations unfairly by attaching this phrase to a feature that may not actually arrive soon. (add [skip style guide checks] to commit message to skip)

When you select **Create new token**, a new API token will be created automatically with the following permissions:

Expand Down
11 changes: 11 additions & 0 deletions src/content/docs/workers/ci-cd/builds/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ When connecting a repository to a Workers project, the Worker name in the Cloudf

:::

## Automatic project configuration

When you connect a repository that does not have a Wrangler configuration file, [autoconfig](/workers/framework-guides/automatic-configuration/) runs to detect your framework and create a [pull request](/workers/ci-cd/builds/automatic-prs/) to configure your project for Cloudflare Workers.

1. Autoconfig detects your framework and generates the necessary configuration
2. A pull request is created in your repository with the necessary configuration changes
3. A preview deployment is generated so you can test before merging
4. Once you merge the PR, your project is ready for deployment

For details about supported frameworks and what files are created, refer to [Deploy an existing project](/workers/framework-guides/automatic-configuration/). For details about the PRs created, refer to [Automatic pull requests](/workers/ci-cd/builds/automatic-prs/).

## View build and preview URL

You can monitor a build's status and its build logs by navigating to **View build history** at the bottom of the **Deployments** tab of your Worker.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
---
pcx_content_type: concept
title: Deploy an existing project
sidebar:
order: 1
description: Learn how Wrangler automatically detects and configures your project for Cloudflare Workers.
---

import { PackageManagers, WranglerConfig } from "~/components";

Wrangler can automatically detect your framework and configure your project for Cloudflare Workers. This allows you to deploy existing projects with a single command, without manually setting up configuration files or installing adapters.

:::note
Minimum required Wrangler version: **TODO_VERSION**. Check your version by running `wrangler --version`. To update Wrangler, refer to [Install/Update Wrangler](/workers/wrangler/install-and-update/).
:::

## How it works

When you run `wrangler deploy` or `wrangler setup` in a project directory without a Wrangler configuration file, Wrangler will:

1. **Detect your framework** - Analyzes your project to identify the framework you're using
2. **Prompt for confirmation** - Shows the detected settings and asks you to confirm before making changes
3. **Install adapters** - Installs any required Cloudflare adapters for your framework
4. **Generate configuration** - Creates a `wrangler.jsonc` file with appropriate settings
5. **Update package.json** - Adds helpful scripts like `deploy`, `preview`, and `cf-typegen`
6. **Configure git** - Adds Wrangler-specific entries to `.gitignore`

## Supported frameworks

Automatic configuration supports the following frameworks:

| Framework | Adapter/Tool | Notes |
| ---------------------------------------------------------------------------- | ------------------------------ | --------------------------------------------------- |
| [Next.js](/workers/framework-guides/web-apps/nextjs/) | `@opennextjs/cloudflare` | Runs `@opennextjs/cloudflare migrate` automatically. [R2 caching](#nextjs-caching) is configured if available. |
| [Astro](/workers/framework-guides/web-apps/astro/) | `@astrojs/cloudflare` | Runs `astro add cloudflare` automatically |
| [SvelteKit](/workers/framework-guides/web-apps/sveltekit/) | `@sveltejs/adapter-cloudflare` | Runs `sv add sveltekit-adapter` automatically |
| [Nuxt](/workers/framework-guides/web-apps/more-web-frameworks/nuxt/) | Built-in Cloudflare preset | |
| [React Router](/workers/framework-guides/web-apps/react-router/) | Cloudflare Vite plugin | |
| [Solid Start](/workers/framework-guides/web-apps/more-web-frameworks/solid/) | Built-in Cloudflare preset | |
| [Qwik](/workers/framework-guides/web-apps/more-web-frameworks/qwik/) | Built-in Cloudflare adapter | |
| [TanStack Start](/workers/framework-guides/web-apps/tanstack-start/) | Cloudflare Vite plugin | |
| [Angular](/workers/framework-guides/web-apps/more-web-frameworks/angular/) | | |
| [Analog](/workers/framework-guides/web-apps/more-web-frameworks/analog/) | Built-in Cloudflare preset | |
| [Vite](/workers/vite-plugin/) | Cloudflare Vite plugin | |
| [Hono](/workers/framework-guides/web-apps/more-web-frameworks/hono/) | | |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hono is not supported 😓

| [Vike](/workers/framework-guides/web-apps/vike/) | | |
| [Waku](/workers/framework-guides/web-apps/more-web-frameworks/waku/) | | |
| Static sites | None | Any directory with an `index.html` |

## Files created and modified

When automatic configuration runs, the following files may be created or modified:

### `wrangler.jsonc`

A new Wrangler configuration file is created with settings appropriate for your framework:

<WranglerConfig>

```jsonc
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "my-project",
"main": "dist/_worker.js/index.js",
"compatibility_date": "$today",
"compatibility_flags": ["nodejs_compat"],
"assets": {
"binding": "ASSETS",
"directory": "dist",
},
"observability": {
"enabled": true,
},
}
```

</WranglerConfig>

The exact configuration varies based on your framework.

### `package.json`

New scripts are added to your `package.json`:

```json
{
"scripts": {
"deploy": "npm run build && wrangler deploy",
"preview": "npm run build && wrangler dev",
"cf-typegen": "wrangler types"
}
}
```

### `.gitignore`

Wrangler-specific entries are added:

```txt
# wrangler files
.wrangler
.dev.vars*
!.dev.vars.example
```

### `.assetsignore`

For frameworks that generate worker files in the output directory, an `.assetsignore` file is created to exclude them from static asset uploads:

```txt
_worker.js
_routes.json
```

## Using automatic configuration

### Deploy with automatic configuration

To deploy an existing project, run [`wrangler deploy`](/workers/wrangler/commands/#deploy) in your project directory:

<PackageManagers type="exec" pkg="wrangler" args="deploy" />

Wrangler will detect your framework, show the configuration it will apply, and prompt you to confirm before making changes and deploying.

### Configure without deploying

To configure your project without deploying, use [`wrangler setup`](/workers/wrangler/commands/#setup):

<PackageManagers type="exec" pkg="wrangler" args="setup" />

This is useful when you want to review the generated configuration before deploying.

### Preview changes with dry run

To see what changes would be made without actually modifying any files:

<PackageManagers type="exec" pkg="wrangler" args="setup --dry-run" />

This outputs a summary of the configuration that would be generated.

## Non-interactive mode

To skip the confirmation prompts, use the [`--yes` flag](/workers/wrangler/commands/#deploy):

<PackageManagers type="exec" pkg="wrangler" args="deploy --yes" />

This applies the configuration automatically using sensible defaults. This is useful in CI/CD environments or when you want to accept the detected settings without reviewing them.

## Importing a repository from the dashboard

When you import a GitHub or GitLab repository via the Cloudflare dashboard, autoconfig runs non-interactively. If your repository does not have a Wrangler configuration file, [Workers Builds](/workers/ci-cd/builds/) will create a pull request with the necessary configuration.

The PR includes all the configuration changes described above. A preview deployment is generated so you can test the changes before merging. Once merged, your project is ready for deployment.

For more details, refer to [Automatic pull requests](/workers/ci-cd/builds/automatic-prs/).

## Skipping automatic configuration

If you do not want automatic configuration to run, ensure you have a valid Wrangler configuration file (`wrangler.toml`, `wrangler.json`, or `wrangler.jsonc`) in your project before running `wrangler deploy`.

You can also manually configure your project by following the framework-specific guides in the [Framework guides](/workers/framework-guides/).

## Next.js caching

For Next.js projects, automatic configuration will set up [R2](/r2/) for caching if your Cloudflare account has R2 enabled. R2 caching improves performance for [Incremental Static Regeneration (ISR)](https://opennext.js.org/cloudflare/caching) and other Next.js caching features.

- **If R2 is enabled on your account**: Automatic configuration creates an R2 bucket and configures caching automatically.
- **If R2 is not enabled**: Your project will be configured without caching. You can [enable R2](/r2/get-started/) later and manually configure caching by following the [OpenNext caching documentation](https://opennext.js.org/cloudflare/caching).

To check if R2 is enabled or to enable it, go to **Storage & Databases** > **R2** in the [Cloudflare dashboard](https://dash.cloudflare.com/).

## Troubleshooting

### Multiple frameworks detected

When you import a repository via [Workers Builds](/workers/ci-cd/builds/) in the Cloudflare dashboard, automatic configuration will fail if your project contains multiple frameworks. To resolve this, set the [root directory](/workers/ci-cd/builds/configuration/#build-settings) to the path containing only one framework. For monorepos, refer to [monorepo setup](/workers/ci-cd/builds/advanced-setups/#monorepos).

When running `wrangler deploy` or `wrangler setup` locally, Wrangler will prompt you to select which framework to use if multiple frameworks are detected.

### Framework not detected

If your framework is not detected, ensure your `package.json` includes the framework as a dependency. If the framework is not in the [supported list](#supported-frameworks), you'll need to manually configure your project.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autoconfig can also work with frameworks that we don't officially support, for example SPAs such as react (vite-based), so possibly we should either clarify that in the supported list or be a bit more vague here.

Suggested change
If your framework is not detected, ensure your `package.json` includes the framework as a dependency. If the framework is not in the [supported list](#supported-frameworks), you'll need to manually configure your project.
If your framework is not detected, ensure your `package.json` includes the framework as a dependency. If the framework is not in the [supported list](#supported-frameworks), you might need to manually configure your project.


### Configuration already exists

If a Wrangler configuration file already exists, automatic configuration will not run. To reconfigure your project, delete the existing configuration file and run `wrangler deploy` or `wrangler setup` again.

### Workspaces

Support for monorepos and npm/yarn/pnpm workspaces is currently limited. Wrangler analyzes the project directory where you run the command, but does not detect dependencies installed at the workspace root. This can cause framework detection to fail if the framework is listed as a dependency in the workspace's root `package.json` rather than in the individual project's `package.json`.

If you encounter issues, report them in the [Wrangler GitHub repository](https://github.com/cloudflare/workers-sdk/issues/new/choose).
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ import {

[![Deploy to Workers](https://deploy.workers.cloudflare.com/button)](https://dash.cloudflare.com/?to=/:account/workers-and-pages/create/deploy-to-workers&repository=https://github.com/cloudflare/templates/tree/main/astro-blog-starter-template)

:::tip[Already have an Astro project?]
You can deploy an existing Astro project to Cloudflare Workers with a single command:

<PackageManagers type="exec" pkg="wrangler" args="deploy" />

Wrangler will automatically detect Astro, install the Cloudflare adapter, and configure your project. Refer to [Deploy an existing project](/workers/framework-guides/automatic-configuration/) for details.
:::

## What is Astro?

[Astro](https://astro.build/) is a JavaScript web framework designed for creating websites that display large amounts of content (such as blogs, documentation sites, or online stores).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ In this guide, you will create a new [Analog](https://analogjs.org/) application

[Analog](https://analogjs.org/) is a fullstack meta-framework for Angular, powered by [Vite](https://vitejs.dev/) and [Nitro](https://nitro.unjs.io/).

:::tip[Already have an Analog project?]
You can deploy an existing Analog project to Cloudflare Workers with a single command:

<PackageManagers type="exec" pkg="wrangler" args="deploy" />

Wrangler will automatically configure your project. Refer to [Deploy an existing project](/workers/framework-guides/automatic-configuration/) for details.
:::

## 1. Set up a new project

Use the [`create-cloudflare`](https://www.npmjs.com/package/create-cloudflare) CLI (C3) to set up a new project. C3 will create a new project directory, initiate Analog's official setup tool, and provide the option to deploy instantly.
Expand Down
Loading
Loading