Serverless Cloudflare Workers banner
cloudflare cloudflare

Serverless Cloudflare Workers

DevOps community

Description

Serverless provider plugin for Cloudflare Workers

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

serverless-cloudflare-workers

Serverless plugin for [Cloudflare Workers](https://developers.cloudflare.com/workers/)

Documentation

https://serverless.com/framework/docs/providers/cloudflare/guide/quick-start/

Bundling with Webpack

You can have the plugin automatically bundle your code into one file using [webpack](https://webpack.js.org/). This is a great solution if you are fine with a no frills bundling.

You can use a single global webpack config to bundle your assets. And this webpack config will be built during the packaging time, before individual functions are prepared. To use this, add `webpackConfig` to your service section in serverless config, with value as the path to the webpack config.

service:
  name: service-name
  webpackConfig: webpack.config #webpack config path without js extension from root folder.
  config:
    accountId: ${env:CLOUDFLARE_ACCOUNT_ID}
    zoneId: ${env:CLOUDFLARE_ZONE_ID}

You can also add a function level webpack configuration in addition to a global webpack configuration. This helps you to process bundling different for an individual function than the global webpack config explained earlier. To use this, set the webpack config path to the function level `webpack` variable. Setting function level `webpack` variable to `true` will force webpack to bundle the function script with a default web pack configuration. Setting `webpack` key to `false` will turn off webpack for the function. (i.e the function script will not be fetched from dist folder)

Simply add `webpack: true | ` to your config block.

functions:
  myfunction:
    name: myfunction
    webpack: true #or the web pack config path for this function
    script: handlers/myfunctionhandler
    events:
      - http:
          url: example.com/myfunction
          method: GET
  

Environment Variables

While Cloudflare Workers doesn't exactly offer environment vairables, we can bind global variables to values, essentia