Skip to content

Template (boilerplate) repository for scaffolding Cloudflare Workers projects.

License

Notifications You must be signed in to change notification settings

pirquessa/cloudflare-starter-kit

 
 

Repository files navigation

Cloudflare Workers Starter Kit

Project template for scaffolding Cloudflare Workers projects.

Features

  • Supports multiple worker scripts within the same project
  • Source code bundling with Babel and Rollup
  • Pre-configured with TypeScript, ESLint, Jest, and Prettier
  • Pre-commit Git hook(s) using Husky; CI/CD workflow (GitHub Actions)
  • Code snippets and other VSCode settings

This project was bootstrapped with Cloudflare Starter Kit. Be sure to join our Discord channel for assistance.

Directory Structure

├──.github — GitHub configuration including CI/CD workflows
├──.vscode — VSCode settings including code snippets, recommended extensions etc.
├──core — core modules and utility functions
├──scripts — Automation scripts, such as yarn deploy
├──workers — Cloudflare Worker scripts
├──bindings.d.ts — KV bindings etc.
├──package.json — npm dependencies and Yarn scripts
├──rollup.config.js — code bundling configuration for Rollup
└──tsconfig.json — TypeScript configuration

Tech Stack

Cloudflare Workers, TypeScript, Babel, ESLint, Prettier, Jest, Yarn v2 with PnP, Rollup.

Requirements

Getting Started

  • Clone the repo
    git clone -o seed https://github.com/kriasoft/cloudflare-starter-kit.git
  • Install project dependencies — yarn install
  • Optionally, configure Husky — yarn setup
  • Add or edit Cloudflare Workers inside of the workers folder
  • Build and deploy them by running yarn build, yarn deploy.

IMPORTANT: Ensure that VSCode is using the workspace versions of TypeScript and ESLint.

Scripts

  • yarn build — Compiles and bundles Cloudflare Workers into the .build folder
  • yarn lint — Validate code using ESLint
  • yarn tsc — Validate code using TypeScript compiler
  • yarn test — Run unit tests with Jest, Supertest
  • yarn deploy — Deploys the app to Cloudflare

How to Deploy

Ensure that Cloudflare account credentials are present in the .env file:

# Cloudflare
# https://dash.cloudflare.com/
# https://developers.cloudflare.com/api/tokens/create
CLOUDFLARE_ACCOUNT_ID=
CLOUDFLARE_ZONE_ID=
CLOUDFLARE_API_TOKEN=

Compile and deploy the app by running:

$ yarn build
$ yarn deploy [--env #0]

Where --env argument is the target environment, e.g. yarn deploy --env=prod.

How to Update

  • yarn set version latest — Bump Yarn to the latest version
  • yarn upgrade-interactive — Update Node.js modules (dependencies)
  • yarn pnpify --sdk vscode — Update TypeScript, ESLint, and Prettier settings in VSCode

Backers 💰

              

Related Projects

How to Contribute

Anyone and everyone is welcome to contribute. Start by checking out the list of open issues marked help wanted. However, if you decide to get involved, please take a moment to review the guidelines.

License

Copyright © 2020-present Kriasoft. This source code is licensed under the MIT license found in the LICENSE file.


Made with ♥ by Konstantin Tarkus (@koistya, blog) and contributors.

About

Template (boilerplate) repository for scaffolding Cloudflare Workers projects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 50.7%
  • TypeScript 48.5%
  • Shell 0.8%