Build your Cloudflare Workers with esbuild.

Overview

build-worker

Bundle your Cloudflare Worker with esbuild instead of webpack. (It's ridiculously faster!)

Wrangler v1 uses webpack.
Wrangler v2 is using esbuild.

Problem: Wrangler 2 is not production-ready.
Solution: build-worker.

Usage

  1. Install.
    npm install build-worker
    
  2. Add a package.json script.
    // package.json
    {
      scripts: {
        'build:worker': 'build-worker --entry worker.js --out dist/worker.js --debug'
      }
    }

    The --debug flag disables minification, making debugging much easier.

  3. Run your script.
    npm run build:worker

It can also be used programmatically:

import { buildWorker } from 'build-worker'
await buildWorker({ entry: 'worker.js' , out: 'dist/worker.js', debug: false })

IS_CLOUDFLARE_WORKER

build-worker replaces any occurrences of IS_CLOUDFLARE_WORKER with true, which your code can use to determine whether its being run in a Cloudflare Worker:

if (IS_CLOUDFLARE_WORKER !== 'undefined' && IS_CLOUDFLARE_WORKER === true) {
  // Do something that should only happen in Cloudflare Workers
} else {
  // Do something that should not happen in Cloudflare Workers
}

How it works

build-worker uses the same esbuild configuration than Wrangler 2.

See evanw/esbuild#1189.

You might also like...

Build and deploy a roadmap voting app for your porject

Build and deploy a roadmap voting app for your porject

Roadmap Voting App You can deploy Roadmap application yourself and get feedback from your users about your roadmap features. See the live example. In

Jan 3, 2023

generate statistics on the number of audience minutes your site is generating, and if readers make it to the end of your screeds

generate statistics on the number of audience minutes your site is generating, and if readers make it to the end of your screeds

audience-minutes generate statistics on the number of audience minutes your site is receiving, and if readers make it to the end of your screeds. β€œIf

Dec 28, 2022

⚑️ Supercharge your ViewComponent development process πŸš€

⚑️ Supercharge  your ViewComponent development process πŸš€

L πŸ‘€ kbook ⚑️ Supercharge your ViewComponent development process πŸš€ About Lookbook provides a ready-to-go UI for navigating, inspecting and interactin

Dec 26, 2022

Out of the box modern User Interface, so you can see and manage your Workhorse jobs in realtime

Out of the box modern User Interface, so you can see and manage your Workhorse jobs in realtime

WORKHORSE UI Out of the box modern User Interface, so you can see and manage your Workhorse jobs in realtime. Start local Run npm i Copy and name prox

Apr 15, 2022

A Remix.run stack to monitor your BullMQ queues

A Remix.run stack to monitor your BullMQ queues

Remix Matador stack A bold interface that helps you monitor your BullMQ queues. Learn more about Remix Stacks. $ npx create-remix@latest --template nu

Dec 15, 2022

Adds clap button (like medium) to any page for your Next.js apps.

Adds clap button (like medium) to any page for your Next.js apps.

@upstash/claps Add a claps button (like medium) to any page for your Next.js apps. Nothing to maintain, it is completely serverless πŸ’― Check out the d

Nov 23, 2022

A bot that notifies you on Slack whenever your company/product is mentioned on Hacker News. Powered by Vercel Functions & Upstash.

A bot that notifies you on Slack whenever your company/product is mentioned on Hacker News. Powered by Vercel Functions & Upstash.

Hacker News Slack Bot A bot that notifies you on Slack whenever your company/product is mentioned on Hacker News. or deploy your own Built With Vercel

Jan 3, 2023

Use Cloudflare Workers Cron Triggers to keep your Hetzner Cloud Firewall allowing the latest list of Cloudflare IPs, or any other lists!

Hetzner Cloud Firewall automation with Cloudflare Workers Heavily inspired by xopez/Hetzner-Cloud-Firewall-API-examples, this repository holds a Cloud

Dec 17, 2022

Functional-style Cloudflare Durable Objects with direct API calls from Cloudflare Workers and TypeScript support.

durable-apis Simplifies usage of Cloudflare Durable Objects, allowing a functional programming style or class style, lightweight object definitions, a

Jan 2, 2023

Lightweight and versatile build tool based on the esbuild compiler

Lightweight and versatile build tool based on the esbuild compiler

Estrella is a lightweight and versatile build tool based on the fantastic esbuild TypeScript and JavaScript compiler. Rebuild automatically when sourc

Jan 2, 2023

Google-Drive-Directory-Index | Combining the power of Cloudflare Workers and Google Drive API will allow you to index your Google Drive files on the browser.

🍿 Google-Drive-Directory-Index Combining the power of Cloudflare Workers and Google Drive will allow you to index your Google Drive files on the brow

Jan 2, 2023

A flexible gateway for running ML inference jobs through cloud providers or your own GPU. Powered by Replicate and Cloudflare Workers.

Cogflare (Working title) Cogflare is a Cloudflare Workers application that aims to simplify running distributed ML inference jobs through a central AP

Dec 12, 2022

An esbuild plugin to inject your application's version number or today's date into your files

esbuild-plugin-version-injector An esbuild plugin to inject your application's version number or today's date into your files This plugin was inspired

Dec 6, 2022

基于 gh-proxy + Jsdelivr+ cnpmjs + cloudflare workers ηš„ GitHub Serverless API ε·₯具。

better-github-api Better, Eazy, Access Anywhere 介绍 基于 gh-proxy + Jsdelivr + cnpmjs + cloudflare workers ηš„ GitHub Serverless API ε·₯具。 cdn.jsοΌšδ»…ε« gh-proxy

Nov 23, 2022

Cloudflare Workers Discord embed & keep URL example scripts.

Using Cloudflare Workers for Discord embed support Requirements: Your own image host, on a domain that you control via Cloudflare. Limitations: 100,00

Dec 27, 2022

πŸ”₯ Miniflare is a simulator for developing and testing Cloudflare Workers.

πŸ”₯ Miniflare is a simulator for developing and testing Cloudflare Workers.

Jan 3, 2023

slash-create with Cloudflare Workers template

/create with Cloudflare Workers A slash-create template, using Cloudflare Workers. Getting Started Cloning the repo You can either use degit to locall

Jan 3, 2023

Airtable + Cloudflare Workers URL Shortener 🌀

Airtable + Cloudflare Workers URL Shortener 🌀

tableflare Airtable + Cloudflare Workers URL Shortener 🌀 Quick Start Airtable Generate your Airtable API key from your account dashboard: https://air

Oct 16, 2022

βš”οΈ Strongly-typed Discord commands on Cloudflare Workers

βš”οΈ Strongly-typed Discord commands on Cloudflare Workers

βš”οΈ Slshx Slshx is a slightly wacky, experimental, library for building strongly-typed Discord commands that run on Cloudflare Workers, using a React-i

Dec 26, 2022
Owner
Rom
Rom
slash-create with Cloudflare Workers template

/create with Cloudflare Workers A slash-create template, using Cloudflare Workers. Getting Started Cloning the repo You can either use degit to locall

Snazzah 13 Jan 3, 2023
Airtable + Cloudflare Workers URL Shortener 🌀

tableflare Airtable + Cloudflare Workers URL Shortener ?? Quick Start Airtable Generate your Airtable API key from your account dashboard: https://air

Griko Nibras 10 Oct 16, 2022
Store and Deliver images with R2 backend Cloudflare Workers.

r2-image-worker Store and Deliver images with Cloudflare R2 backend Cloudflare Workers. Synopsis Deploy r2-image-worker to Cloudflare Make a base64 st

Yusuke Wada 62 Jan 3, 2023
Cloudflare Worker that will allow you to progressively migrate files from an S3-compatible object store to Cloudflare R2.

A Cloudflare Worker for Progressive S3 to R2 Blog Post: https://kian.org.uk/progressive-s3-to-cloudflare-r2-migration-using-workers/ This is a Cloudfl

Kian 29 Dec 30, 2022
Making service workers easy so that your app is fast and reliable, even offline.

tulo.js Making service workers easy to use so that your app can be fast and reliable, even offline. Welcome to tulo.js, a service worker library that

OSLabs Beta 37 Nov 16, 2022
Example repo for getting NextJS, Rust via wasm-pack, and web workers all playing nicely together.

Example of integrating WASM & web workers with a Typescript NextJS project. Running yarn yarn dev Open localhost:3000 Layout Rust code is in ./rust, g

Studio Lagier 63 Dec 23, 2022
Easily redirect one entire domain to another with a serverless Cloudflare Worker.

Domain Redirecting with Cloudflare Workers Easily redirect one entire domain to another with a serverless Cloudflare Worker. All paths and other data

Erisa A 19 Dec 11, 2022
Send emails using Cloudflare Worker, for free.

Email API for Proselog. Not intended for use outside of Proselog, but it should work with any worker, without any configuration. import { sendEmail }

Proselog 65 Nov 7, 2022
Cloudflare Worker to make a R2 Bucket public!

r2-public-worker A Cloudflare Worker to make your R2 bucket public! Minimum Requirements Cloudflare Account wrangler >= 2.0.2 Note: Ensure you are usi

Cole Mackenzie 20 Sep 19, 2022
Using Cloudflare worker to generate host list from firebog to keep updated.

AdGuardCloudflareHostGenerator Use a cloudflare worker to generate a up to date list from FireBog's ticked list found at https://v.firebog.net/hosts/l

Jake Steele 14 Nov 30, 2022