cloudflare-workers-template
A Cloudflare Workers template with Typescript and predefined opinionated ESLint and Prettier rules.
Setup
yarn create cloudflare project-name https://github.com/Aynh/cloudflare-workers-template/
# or
npm init cloudflare project-name https://github.com/Aynh/cloudflare-workers-template/
# Clone the repository
git clone https://github.com/Aynh/cloudflare-workers-template/ project-name --depth 1
# Follow the step below if you want to re-initialize the git repository (optional)
cd project-name
# Remove .git folder
rm -rf .git
# Initialize git
git init .
Install dependencies
yarn
# or
npm install
Available scripts
Subsitute yarn
with npm run
if you use npm
.
# Local development
yarn dev
# Remote development
yarn preview
# Publish to cloudflare
yarn publish
# Lint
yarn lint
# Type check
yarn typecheck
Development
Follow Cloudflare's Get started guide if you haven't already.
This template leverage Wrangler2's module system to work, See here if you are not familiar with Cloudflare Worker's Module Worker format.
You may want to replace some (or all) ESLint rules defined at .eslintrc.cjs
. You can also remove linting entirely by deleting .eslintrc.cjs
and removing all ESLint-related dependency.
You may also want replace Prettier rules at .prettierrc.json
.
Recommended Package
- itty-router, nice tiny router to integrate with your worker.
Learning source