Skip to content

helloimalastair/WorkerOnReplit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

👷 worker-template Hello World #NowOnReplit

Run on Repl.it

A template for kick starting a Cloudflare worker project, optimized for use in Replit.

Learn more about Workers

src/index.js is the content of the Workers script.

Commands

Here are some commands that this repo comes with. Feel free to add your own, or add a Pull Request to add some to this repo. Note that all these commands must be added to the run field of the .replit file, then press the run button to execute them, and each command must be prefixed with yarn. Also, the default command will automatically build and create a miniflare instance for you.

format

Utilizes Prettier to format your code. Configuration can be edited in the .prettierrc file.

build

Runs Esbuild to build your script. Default is to bundle and minify. Configuration can be edited directly in the command in the package.json.

big

Disables minifying to allow you to debug your code easier.

test

Automatically builds your script, then uses Miniflare to allow you to test your script locally, before deploying.

clean

Removes the built script and node_modules, to allow you to build from scratch.

Convert JS to TS With Type Checking

  • First run the following command in your console.
npx typescript --init
  • Now a tsconfig.json file will be created and now make the following changes.
  1. Make outDir: './dist'
  2. Make rootDir: './src'
  3. Uncomment the following attibute named moduleResolution.
  4. Uncomment the attribute CheckJS so that it enables ts to type check for your js files.
  • Now you can just rename your js file to ts.

  • Check for the modules that you imported whether it supports both natively, if not them install it using @types. For example if express has no definations and is a seperate module for TS, then you can install it following this snippet.

npx -i -D typescript @cloudflare/workers-types

Update the scripts in packages.json by adding tsc && to the front of all commands.

  • Make sure in your js file you change your variable type to 'Any'.

  • Now you can just refactor the code according to make it to TS.

  • If you are facing problems and not able to execute these steps. Click on this Link.

About

Replit Template for building with Cloudflare Workers

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published