diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index 59749d330c..a4fd5ae318 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -197,6 +197,7 @@ const guideSidebar = [ items: [ { text: 'IDE Integration', link: '/guide/ide-integration' }, { text: 'CI', link: '/guide/ci' }, + { text: 'Cloudflare Workers Builds', link: '/guide/cloudflare-workers' }, { text: 'Docker', link: '/guide/docker' }, ], }, diff --git a/docs/guide/ci.md b/docs/guide/ci.md index dc13c840f5..0f04f66323 100644 --- a/docs/guide/ci.md +++ b/docs/guide/ci.md @@ -6,6 +6,8 @@ You can use `voidzero-dev/setup-vp` to use Vite+ in CI environments. [`voidzero-dev/setup-vp`](https://github.com/voidzero-dev/setup-vp) provides integrations for GitHub Actions, GitLab CI/CD, and Azure Pipelines. All three install Vite+, can select the project's Node.js version, and can install project dependencies. The GitHub Action and Azure Pipelines template can also cache package-manager data automatically. GitLab CI/CD uses the job's native cache configuration and requires Node.js to start the setup runtime. +For a Git-connected Cloudflare Worker, see [Cloudflare Workers Builds](/guide/cloudflare-workers) for the build and deploy commands. + ## setup-vp Versioning Set `` in each example to an exact version from the [`setup-vp` releases page](https://github.com/voidzero-dev/setup-vp/releases). You can use a commit SHA instead. Do not use the `v1` tag. The `v1` tag no longer receives updates. diff --git a/docs/guide/cloudflare-workers.md b/docs/guide/cloudflare-workers.md new file mode 100644 index 0000000000..b852cab08c --- /dev/null +++ b/docs/guide/cloudflare-workers.md @@ -0,0 +1,45 @@ +# Cloudflare Workers Builds + +When you connect a Git repository to Cloudflare Workers Builds, you can use your project's copy of `vp` for both the build and deploy commands. Cloudflare does not list a global `vp` in its [build image](https://developers.cloudflare.com/workers/ci-cd/builds/build-image/). + +## Configure the build and deploy commands + +1. Add [`vite-plus` as a development dependency](/guide/local-cli#manual-installation) and commit your lockfile. Leave automatic dependency installation enabled so Workers Builds installs `vp` in `node_modules/.bin` before the build starts. This works with any package manager configured to use `node_modules`. +2. Use the `build` and `deploy` scripts in your `package.json`. Keep any framework-specific steps your project already uses. For example, a Worker that builds with Vite and deploys with Wrangler can use the following scripts. + + ```json [package.json] + { + "scripts": { + "build": "vp build", + "deploy": "wrangler deploy" + } + } + ``` + + This example uses `wrangler` from the project's development dependencies. For help configuring Vite for your Worker, see [Vite+ on Workers](https://developers.cloudflare.com/workers/vite-plugin/vite-plus/). + +3. In the Cloudflare dashboard, open your Worker and enter the following commands under [**Settings > Build**](https://developers.cloudflare.com/workers/ci-cd/builds/configuration/). + + | Setting | Value | + | -------------- | ----------------------------------- | + | Build command | `./node_modules/.bin/vp run build` | + | Deploy command | `./node_modules/.bin/vp run deploy` | + +Both paths are relative to the **Root directory** in your build settings. If a monorepo installs `vite-plus` at the workspace root, adjust the path to its `node_modules/.bin/vp` in both fields. The `run` subcommand executes the [named project script](/guide/run). + +## Install dependencies with `vp install` + +If you want `vp` to install dependencies, set `SKIP_DEPENDENCY_INSTALL` to `1` under **Settings > Build > Build Variables and Secrets**. This skips Cloudflare's automatic install. Set **Build command** to `bash scripts/workers-build.sh` and commit the following script. + +```bash [scripts/workers-build.sh] +set -euo pipefail + +export VP_HOME="$HOME/.vite-plus" +export PATH="$VP_HOME/bin:$PATH" +curl -fsSL https://vite.plus | bash + +vp install --frozen-lockfile +vp run build +``` + +Keep **Deploy command** set to `./node_modules/.bin/vp run deploy`. The install step makes the project-local CLI available to the deploy command. To pin the CLI used for installation, set the [`VP_VERSION` build variable](/guide/global-cli#vp-version) to an exact release.