{"id":15715311,"url":"https://github.com/cloudflare/serverless-cloudflare-workers","last_synced_at":"2025-04-09T05:09:54.130Z","repository":{"id":33651018,"uuid":"145570474","full_name":"cloudflare/serverless-cloudflare-workers","owner":"cloudflare","description":"Serverless provider plugin for Cloudflare Workers","archived":false,"fork":false,"pushed_at":"2024-09-25T22:40:49.000Z","size":172,"stargazers_count":175,"open_issues_count":37,"forks_count":36,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-02T04:02:58.651Z","etag":null,"topics":["cloudflare","serviceworkers","workers"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudflare.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-21T13:50:45.000Z","updated_at":"2024-09-20T01:53:14.000Z","dependencies_parsed_at":"2024-01-03T02:24:51.148Z","dependency_job_id":"9a0b74eb-09ed-49c1-b802-59879fab709d","html_url":"https://github.com/cloudflare/serverless-cloudflare-workers","commit_stats":{"total_commits":34,"total_committers":11,"mean_commits":3.090909090909091,"dds":0.5882352941176471,"last_synced_commit":"e93ec702290b6adb67acea1371904136d5984d93"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fserverless-cloudflare-workers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fserverless-cloudflare-workers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fserverless-cloudflare-workers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fserverless-cloudflare-workers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudflare","download_url":"https://codeload.github.com/cloudflare/serverless-cloudflare-workers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980837,"owners_count":21027808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare","serviceworkers","workers"],"created_at":"2024-10-03T21:40:54.751Z","updated_at":"2025-04-09T05:09:54.111Z","avatar_url":"https://github.com/cloudflare.png","language":"JavaScript","funding_links":[],"categories":["Frameworks \u0026 Libraries","Serverless Framework Plugins","JavaScript"],"sub_categories":["Language Support"],"readme":"# serverless-cloudflare-workers\n\nServerless plugin for [Cloudflare Workers](https://developers.cloudflare.com/workers/)\n\n## Documentation\n\nhttps://serverless.com/framework/docs/providers/cloudflare/guide/quick-start/\n\n### Bundling with Webpack\n\nYou 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.\n\nYou 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.\n\n```yaml\nservice:\n  name: service-name\n  webpackConfig: webpack.config #webpack config path without js extension from root folder.\n  config:\n    accountId: ${env:CLOUDFLARE_ACCOUNT_ID}\n    zoneId: ${env:CLOUDFLARE_ZONE_ID}\n\n```\n\nYou 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)\n\nSimply add `webpack: true | \u003cconfig path\u003e` to your config block.\n\n```yaml\nfunctions:\n  myfunction:\n    name: myfunction\n    webpack: true #or the web pack config path for this function\n    script: handlers/myfunctionhandler\n    events:\n      - http:\n          url: example.com/myfunction\n          method: GET\n  \n```\n\n### Environment Variables\n\nWhile Cloudflare Workers doesn't exactly offer environment vairables, we can bind global variables to values, essentially giving the same capabilities. In your function configuration, add key value pairs in `environment`\n\n```yaml\nfunctions:\n  myFunction:\n    environment:\n      MYKEY: value_of_my_key\n      ANOTHER_KEY_OF_MINE: sweet_child_o_mine\n\n```\n\nThen in your script, you can reference `MYKEY` to access the value.\n\nYou can also add an environment block under `provider`. These will get added to every function. If a function defines the same variable, the function defintion will overwrite the provider block definition.\n\n```yaml\nprovider:\n  name: cloudflare\n  environment:\n    MYKEY: value_of_my_key\n    ANOTHER_KEY_OF_MINE: sweet_child_o_mine\n\n```\n\n### Using Cloudflare KV Storage\n\nThe plugin can create and bind a [KV Storage](https://developers.cloudflare.com/workers/kv/) namespace for your function by simpling adding a resources section.\n\nThe following will create a namespace called `BEST_NAMESPACE` and bind the variable `TEST` to that namespace inside `myfunction`.\n\n```yaml\nfunctions:\n  myfunction:\n    name: myfunction\n    webpack: true\n    script: handlers/myfunctionhandler\n    resources:\n      kv:\n        - variable: TEST\n          namespace: BEST_NAMESPACE\n    events:\n      - http:\n          url: example.com/myfunction\n          method: GET\n```\n\n### Web Assembly\n\nThe plugin can upload and bind WASM to execute in your worker. The easiest way to do this is to use the --template cloudflare-workers-rust when generating a project. The template includes a Rust create folder setup with wasm-pack, a webpack script for adding the generated javascript into your project, and the yml file settings to upload the wasm file itself.\n\n```yaml\nfunctions:\n  myfunction:\n    name: myfunction\n    webpack: true\n    script: handlers/myfunctionhandler\n    resources:\n      wasm:\n        - variable: WASM\n          filename: rust/pkg/wasm_bg.wasm\n    events:\n      - http:\n          url: example.com/myfunction\n          method: GET\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudflare%2Fserverless-cloudflare-workers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudflare%2Fserverless-cloudflare-workers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudflare%2Fserverless-cloudflare-workers/lists"}