Cloudflare Worker Webpack Plugin

Deploy freshly-bundled Cloudflare Worker scripts and route matching patterns directly from your build step 🚀

Example as implemented in Cloudflare Worker Webpack Boilerplate

Usage

Install, ...

npm install -D cloudflare-worker-webpack-plugin

... require...

const CloudflareWorkerPlugin = require ( ' cloudflare-worker-webpack-plugin ' ) ;

... and include the plugin in your webpack dark arts configuration:

plugins : [ new CloudflareWorkerPlugin ( $CLOUDFLARE_AUTH_EMAIL , $CLOUDFLARE_AUTH_KEY , { site : ` your-site.lol ` , enabledPatterns : ` omg.your-site.lol/*,example.your-site.lol/crazy/pattern/* ` , disabledPatterns : ` example.your-site.lol/crazy/pattern/ignore-me-tho ` , verbose : true , } ) , ] ,

Configuration

Required Configuration

Cloudflare Credentials

$CLOUDFLARE_AUTH_EMAIL : Your Cloudflare user email.

: Your Cloudflare user email. $CLOUDFLARE_AUTH_KEY : Your Cloudflare super-duper-secret API key.

Cloudflare Zone

You must provide one of the following two options:

zone : Zone ID of the domain for which you're deploying your script OR

site : Fully-qualified domain name (FQDN) of your target deployment zone.

Note: If both zone and site are provided, zone wins.

Options

enabledPatterns : a single route matching pattern, a comma-separated list of patterns, or an Array of patterns to enable for your newly spawned JavaScript minion (default: undefined ) Example (string): "*.your-site.lol" Example (list): "*.your-site.lol,your-site.lol/some-pattern/*" Example (Array): ["*.your-site.lol", "your-site.lol/some-pattern/*"]

: a single route matching pattern, a comma-separated list of patterns, or an Array of patterns to enable for your newly spawned JavaScript minion (default: ) disabledPatterns : same as enabledPatterns above, but the worker will ignore requests matching these patterns.

: same as above, but the worker will requests matching these patterns. script : relative path to your worker script (default: <webpack-config-output-file> )

: path to your worker script (default: ) metadataPath : Optional relative path to a JSON metadata file with e.g. secrets (default: undefined )

: Optional path to a JSON metadata file with e.g. secrets (default: ) skipWorkerUpload : Skip uploading the worker script and process only route patterns (default: false )

: Skip uploading the worker script and process only route patterns (default: ) reset : Delete ALL route patterns, DELETE existing worker script, and exit (default: false )

: Delete ALL route patterns, DELETE existing worker script, and exit (default: ) verbose : Log additional information about each deployment step to the console (default: false )

: Log additional information about each deployment step to the console (default: ) colors : Use colors in console output (default: false )

: Use colors in console output (default: ) emoji : Use emoji in console output (default: false )

: Use emoji in console output (default: ) enabled : Whether to deploy to Cloudflare or bypass; useful for e.g. CI and testing (default: true )

Note: Any existing patterns not found in enabledPatterns or disabledPatterns will be deleted!

Potential Issues

This plugin does not support features reserved for Enterprise Cloudflare Workers.

Contributing

PR's are very much welcome. Here are some fun ideas to consider:

Write hella' cool automated tests

Write hella' cool automated tests Support other neat Cloudflare Worker features like Workers KV and wasm

Feel free to create an issue throwing your own ideas at me.

Because Software

Neat Little Badges

Disclaimer

Besides 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