Workers Webpack & Rollup Examples

Cloudflare Workers allow you to write JavaScript which runs on all of Cloudflare's 160+ global data centers.

  • This repo is an example of how to combine multiple files and dependencies to create a Worker using the Webpack or Rollup build tools.
  • The sample Worker (src/index.js) replaces the content of your site with a Worker which returns the current time in the timezone of the caller's choice.
  • Once you've created your bundle, you can test it without leaving your text editor! Just run npm run preview url=https://google.com?tz=America/New_York

Dependencies

  • npm
  • jq (for the preview script)
  • cURL (for the preview script)

Instructions

git clone https://github.com/obezuk/cf-worker-aws-fetch.git
cd cf-worker-aws-fetch
npm install

Note: the Rollup config in this project supports Node-style require() and ES6 `import

# Build with Webpack
npm run build

# Build with Rollup (ES6 modules)
npm run rollup

# Build with Rollup (CommonJS)
npm run rollup:cjs

# Build with Rollup (UMD)
npm run rollup:umd
# Open the Workers preview with the built Worker:
npm run preview url=https://www.cloudflare.com