cloudflare-bundler v0.2.3
cloudflare-bundler
Generate a bundle that runs as a Cloudflare worker, then upload it to Cloudflare.
The bundle is minified by default.
const { bundleWorker } = require('cloudflare-bundler')
// Bundle the worker, then upload to Cloudflare.
const worker = await bundleWorker({
  main: 'workers/foo.ts',
  upload: true,
})
// Write the sourcemap.
const fs = require('fs')
fs.writeFileSync(
  'workers/foo.js.map',
  JSON.stringify(worker.map)
)Install
yarn add -D cloudflare-bundlerOptions
- main?: string
 The entry module in JavaScript or TypeScript.
- root?: string
 The root directory of the worker.- This option is useful when your worker has its own - package.jsonand- worker.tomlfiles. The- mainoption is inferred from its- package.jsonfile, and the- uploadoption is inferred from its- worker.tomlfile.- If - mainis undefined, this option is required.
- plugins?: RollupPlugin[]
 Custom plugins to apply after the default plugins (but before minifying).
- serveGlobs?: string[] | { [root: string]: string[] }
 Matching files are bundled with the script. Use the- servefunction (exported by this plugin) in your script to easily serve the bundled content with the proper response headers (- ETag,- Content-Type,- Content-Length).- When an array is passed, the globs are relative to the - rootoption (or the working directory if- rootis undefined).
- minify?: object | boolean
 Customize how the script is minified, or pass- falseto disable minification.
- minifyHtml?: object | boolean
 Customize how inlined- .htmlmodules are minified, or pass- falseto disable.
- upload?: UploadConfig
 When defined, the worker is uploaded after a successful build.- The - UploadConfigtype contains these values:- scriptId: string(any name you like)
- accountId: string(found on the homepage of your Cloudflare account)
- authToken?: string(defaults to- process.env.CLOUDFLARE_AUTH_TOKEN)