vite-plugin-cloudflare-worker v0.1.2
vite-plugin-cloudflare-worker
Generate a bundle that runs as a Cloudflare worker, then write it to disk and/or upload it directly to Cloudflare.
The bundle is minified by default.
import workerPlugin from 'vite-plugin-cloudflare-worker'
export default {
plugins: [
// Make sure this is last.
workerPlugin({
main: 'workers/foo.ts',
}),
]
}Install
yarn add -D vite-plugin-cloudflare-worker@nextConfiguration
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 ownpackage.jsonandworker.tomlfiles. Themainoption is inferred from itspackage.jsonfile, and theuploadoption is inferred from itsworker.tomlfile. Ifmainis undefined, this option is required.dest?: string
The bundle filename, relative tooutDirin Vite config.
Defaults toworkers/[name].jsunlessuploadis defined (in which case, nothing is saved to disk whendestis undefined).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 theservefunction (exported by this plugin) in your script to easily serve the bundled content with the proper response headers (ETag,Content-Type,Content-Length).minify?: object | boolean
Customize how the script is minified, or passfalseto disable minification.minifyHtml?: object | boolean
Customize how inlined.htmlmodules are minified, or passfalseto disable.upload?: UploadConfig
When defined, the worker is uploaded after a successful build.
TheUploadConfigtype contains these values:scriptId: string(any name you like)accountId: string(found on the homepage of your Cloudflare account)authToken?: string(defaults toprocess.env.CLOUDFLARE_AUTH_TOKEN)
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago