All Projects → detroitenglish → Cloudflare Workers Webpack Boilerplate

detroitenglish / Cloudflare Workers Webpack Boilerplate

Licence: mit
A superbly simple, minimal-config template for building, bundling and deploying Cloudflare Workers with Webpack 🚀

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Cloudflare Workers Webpack Boilerplate

Phaser3 Tilemap Pack
Phaser 3 Project Template with Webpack, Tilemap, and Asset Pack
Stars: ✭ 87 (-13.86%)
Mutual labels:  webpack, boilerplate, template
Frontend Boilerplate
An ES20XX starter with common frontend tasks using Webpack 4 as module bundler and npm scripts as task runner.
Stars: ✭ 224 (+121.78%)
Mutual labels:  webpack, boilerplate, template
React Core Boilerplate
Powerful ASP.NET Core 3 templates with React, true server-side rendering and Docker support
Stars: ✭ 169 (+67.33%)
Mutual labels:  webpack, boilerplate, template
Razzle Material Ui Styled Example
Razzle Material-UI example with Styled Components using Express with compression
Stars: ✭ 117 (+15.84%)
Mutual labels:  webpack, boilerplate, template
Secure Electron Template
The best way to build Electron apps with security in mind.
Stars: ✭ 623 (+516.83%)
Mutual labels:  webpack, boilerplate, template
Serverless Prisma
AWS Serverless Prisma Boilerplate
Stars: ✭ 126 (+24.75%)
Mutual labels:  webpack, serverless, boilerplate
Vue Element Starter
Vue starter with Element-UI [READY, unmaintained now]
Stars: ✭ 216 (+113.86%)
Mutual labels:  webpack, boilerplate, template
Gas Clasp Starter
A starter template for Google Apps Script by clasp
Stars: ✭ 184 (+82.18%)
Mutual labels:  webpack, boilerplate, template
React App
Create React App with server-side code support
Stars: ✭ 614 (+507.92%)
Mutual labels:  webpack, boilerplate, template
React Starter Kit
React Starter Kit — front-end starter kit using React, Relay, GraphQL, and JAM stack architecture
Stars: ✭ 21,060 (+20751.49%)
Mutual labels:  webpack, boilerplate, cloudflare
React Firebase Admin
React ⚛️ starter kit with Firebase 🔥 and Bulma for setting up an admin dashboard - Highly scalable, PWA, Serverless
Stars: ✭ 232 (+129.7%)
Mutual labels:  serverless, boilerplate, template
Suicrux
🚀 Ultimate universal starter with lazy-loading, SSR and i18n. [not maintained]
Stars: ✭ 958 (+848.51%)
Mutual labels:  webpack, boilerplate, template
Commerceql
UNMAINTAINED
Stars: ✭ 217 (+114.85%)
Mutual labels:  serverless, boilerplate, template
Awesome Chrome Extension Boilerplate
Use react + typescript + webpack to enhance your chrome extension development experience
Stars: ✭ 146 (+44.55%)
Mutual labels:  webpack, boilerplate, template
Worker Typescript Template
ʕ •́؈•̀) TypeScript template for Cloudflare Workers
Stars: ✭ 129 (+27.72%)
Mutual labels:  cloudflare, boilerplate, template
Graphql Starter
💥 Monorepo template (seed project) pre-configured with GraphQL API, PostgreSQL, React, Relay, and Material UI.
Stars: ✭ 3,377 (+3243.56%)
Mutual labels:  cloudflare, boilerplate, template
Cloudflare Workers Webpack Plugin
Launch Cloudflare Workers to the Edge from the comfort of your build step 🚀
Stars: ✭ 18 (-82.18%)
Mutual labels:  webpack, serverless, cloudflare
Express React Boilerplate
🚀🚀🚀 This is a tool that helps programmers create Express & React projects easily base on react-cool-starter.
Stars: ✭ 32 (-68.32%)
Mutual labels:  webpack, boilerplate, template
React Ssr Boilerplate
A boilerplate for server-side rendered React Applications. Includes local auth and GitHub Oauth 2 strategies.
Stars: ✭ 85 (-15.84%)
Mutual labels:  webpack, boilerplate
React Webpack Babel
Simple React Webpack Babel Starter Kit
Stars: ✭ 1,241 (+1128.71%)
Mutual labels:  webpack, boilerplate

Webpack Boilerplate for Cloudflare Workers

A superbly simple, minimal-config launchpad to build, bundle and deploy Cloudflare Workers with Webpack 🚀

Deploying the example script in a terminal

Why this is

Webpack is the recommended means for Cloudflare Worker developers to leverage npm's massive, modular ecosystem. But to those unfamiliar with Webpack's black magic configuration, it can mean investing countless hours in tooling-tweaks and .*rc-file-fiddling.

So the goal, here, is to provide a fiddle-free, Webpack-powered launchpad with default settings sane enough for almost any use case.

It'll bundle up your script and dependencies, upload your Worker to Cloudflare, and even activate its route(s). The world's now yours to require('🌍')

What you configure

  • Your Cloudflare credentials
  • Your site name (FQDN) or Cloudflare Zone-Id
  • (Optional) One or more route matching patterns for your Worker

What you get

  • Transparent, optimized and ready-to-rock Webpack configuration file
  • Babel configuration ensuring development-setup build compatibility for Node 8+ and script compatibility with the latest V8 runtime
  • On-demand polyfilling in the (very unlikely) event that it's needed
  • Baked-in management of route patterns
  • Minification of Worker scripts to keep them under the 1MB limit
  • A deployable example to demonstrate require and other neat features
  • Access to secret keys, tokens, and certificates using CF-Worker secrets vault
  • Namespace resource bindings for the funky-fresh new Workers KV 👏

Requirements

  • Node 8 or later
  • Cloudflare account with domain

Quick Start

  1. Clone this repository:

    git clone [email protected]:detroitenglish/cloudflare-workers-webpack-boilerplate.git
    
    cd cloudflare-workers-webpack-boilerplate
    
  2. Rename example.env to .env , and add your required Cloudflare credentials, and either your site name or site's zone-id.

  3. Install dependencies with npm install

  4. Write your worker script in src/worker.js

    • Install any dependencies for your worker with: npm install -P <some-npm-module>
    • Build a preview of your bundled worker script in dist/bundled-worker.js by running: npm run build
  5. Build, bundle and launch your minion Worker to the Cloudflare Edge 🚀 using: npm run deploy

Example Cloudflare Worker

A ready-to-rock example Worker script can be found in src/example.worker.js.

The example Worker require()s lodash.sample, and uses it to randomly choose a translation of the word 'hello'.

It then adds a response header in the form of:

x-worker-greeting: <random-hello>, world!

Using the Example Worker

After completing steps 1-3 above, you can build the example script with npm run build:example

You can deploy it live to your site with npm run deploy:example

To get the full experience, create a KV Namespace and add its namespace_id to src/example.metadata.json

Configuration

Required Config

Cloudflare Credentials

The following are required in your .env file:

  • CLOUDFLARE_AUTH_EMAIL: Your Cloudflare account email address

  • CLOUDFLARE_AUTH_KEY: Your Cloudflare API-Key

Site Identification

You must provide a means of identifying your Cloudflare site deployment target by defining (in .env) either:

  • CLOUDFLARE_ZONE_ID: The Zone ID to which your worker will be deployed

or

  • CLOUDFLARE_SITE_NAME: The fully qualified domain name (FQDN) of your site, e.g. example.lol

Additional Config

More options are defined and described in example.env

Default Settings & Behaviors (Advanced)

Minification

Webpack is configured to minify scripts before deployment in order to help keep your bundled Worker under the 1MB limit.

Building previews with npm run build will not minify scripts in order to make debugging easier.

CloudflareWorkerPlugin

Worker script uploading and route pattern management are handled by the this same author's cloudflare-worker-webpack-plugin. You can review the plugin's source code and documentation here.

Babel Configuration

Babel is configured to let you use JavaScript syntaxes and features that are supported in the latest version of Chrome, but not natively supported by NodeJS, e.g. import "statements" or { ...objectSpreadSyntax }.

On build, Babel will only add polyfills to your bundled script if, after evaluating your code, it determines a polyfill is necessary for compatibility with the latest version of Chrome (a very unlikely scenario).

Custom .env Variables

See example.env for details and examples on adding and injecting custom variables.

Cloudflare Worker Secrets Vault

See example.env for details and examples on including a metadata.json secrets file.

Route Patterns

See example.env for details and examples on how route patterns are parsed and deployed.

Relevant Resources

Development

Testing and Issue Reporting

I am not a Cloudflare employee, so as a peasant my testing is limited to my own Workers, in my own zones for my own application in production.

So by all means, try to break stuff! And if something goes kaputt, please let me know by creating an issue.

Contributing

PRs are very much welcome 👍

Committing will trigger - and must pass - linting and a few tests (...which there could be more of!)

Fork away!

Roadmap

Some ideas going forward:

  • [x] Replace zone-id requirement with automatic zone-lookup of FQDN
  • [ ] Setup CI for deployment tests with the Cloudflare API
  • [ ] Support single-shot deployment to multiple zones Meh...
  • [x] Add argument parsing (or actual binary?) for deployment via pure CLI

But I'm very open to suggestions - please share your ideas by creating an issue.

Software Stuff

Disclaimer

Other than a happy customer, I am not affiliated with Cloudflare in any way.

Assume in good faith that I have no idea what I'm doing; REVIEW THE SOURCE, and use at your own risk 🙈

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].