|
| 1 | +# Creating a Project |
| 2 | + |
| 3 | +Use the `uzumibi new` command to create a project for Cloudflare Workers. |
| 4 | + |
| 5 | +## Generating the Project |
| 6 | + |
| 7 | +Create a project named `hello-uzumibi` with the following command: |
| 8 | + |
| 9 | +```bash |
| 10 | +uzumibi new --template cloudflare hello-uzumibi |
| 11 | +``` |
| 12 | + |
| 13 | +Running this command will create a project directory and generate the necessary files: |
| 14 | + |
| 15 | +``` |
| 16 | +Creating project 'hello-uzumibi'... |
| 17 | + generate hello-uzumibi/.gitignore |
| 18 | + generate hello-uzumibi/Cargo.toml |
| 19 | + generate hello-uzumibi/package.json |
| 20 | + generate hello-uzumibi/vitest.config.js |
| 21 | + generate hello-uzumibi/wrangler.jsonc |
| 22 | + generate hello-uzumibi/lib/app.rb |
| 23 | + generate hello-uzumibi/public/assets/index.html |
| 24 | + generate hello-uzumibi/src/index.js |
| 25 | + generate hello-uzumibi/wasm-app/Cargo.toml |
| 26 | + generate hello-uzumibi/wasm-app/build.rs |
| 27 | + generate hello-uzumibi/wasm-app/src/lib.rs |
| 28 | +
|
| 29 | +✓ Successfully created project from template 'cloudflare' |
| 30 | + Run 'cd hello-uzumibi' to get started! |
| 31 | +``` |
| 32 | + |
| 33 | +## Project Directory Structure |
| 34 | + |
| 35 | +The generated project has the following structure: |
| 36 | + |
| 37 | +``` |
| 38 | +hello-uzumibi/ |
| 39 | +├── Cargo.toml # Rust workspace configuration |
| 40 | +├── package.json # Node.js dependencies and scripts |
| 41 | +├── wrangler.jsonc # Wrangler (Cloudflare Workers CLI) configuration |
| 42 | +├── lib/ |
| 43 | +│ └── app.rb # Ruby application code (main) |
| 44 | +├── public/ |
| 45 | +│ └── assets/... # Static assets (HTML, CSS, images, etc.) |
| 46 | +├── src/ |
| 47 | +│ └── index.js # JavaScript glue code (entry point) |
| 48 | +└── wasm-app/ |
| 49 | + ├── Cargo.toml # WASM crate configuration |
| 50 | + ├── build.rs # Build script (compiles Ruby code) |
| 51 | + ├── src/ |
| 52 | + │ └── lib.rs # Rust code for the WASM module |
| 53 | + └── .cargo/ |
| 54 | + └── config.toml # Cargo target settings (may not exist) |
| 55 | +``` |
| 56 | + |
| 57 | +## Role of Each File |
| 58 | + |
| 59 | +### `lib/app.rb` |
| 60 | + |
| 61 | +**This is the main file that developers edit.** You write Uzumibi's routing and request handling logic in Ruby here. |
| 62 | + |
| 63 | +### `src/index.js` |
| 64 | + |
| 65 | +The entry point for Cloudflare Workers. It receives HTTP requests, serializes them to binary format and passes them to the WASM module, then deserializes the response and returns it to the client. Normally, you don't need to edit this file. |
| 66 | + |
| 67 | +### `wasm-app/` |
| 68 | + |
| 69 | +A Rust crate for compiling Ruby code into mruby bytecode and packaging it as a WASM module. Normally, you don't need to edit these files. |
| 70 | + |
| 71 | +- `build.rs` contains configuration to compile `lib/app.rb` into mruby bytecode (`.mrb`) at build time. |
| 72 | +- `src/lib.rs` handles mruby/edge VM initialization and export function definitions. |
| 73 | + |
| 74 | +### `wrangler.jsonc` |
| 75 | + |
| 76 | +The Cloudflare Workers configuration file. It contains the application name, static asset settings, and more. |
| 77 | + |
| 78 | +```jsonc |
| 79 | +{ |
| 80 | + "name": "hello-uzumibi", |
| 81 | + "main": "src/index.js", |
| 82 | + "compatibility_date": "2025-12-30", |
| 83 | + "assets": { |
| 84 | + "directory": "./public", |
| 85 | + "binding": "ASSETS" |
| 86 | + } |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +### `package.json` |
| 91 | + |
| 92 | +Defines npm/pnpm scripts and dependencies. |
| 93 | + |
| 94 | +```json |
| 95 | +{ |
| 96 | + "scripts": { |
| 97 | + "deploy": "wrangler deploy", |
| 98 | + "dev": "cargo build --package hello-uzumibi --target wasm32-unknown-unknown --release && cp -v -f target/wasm32-unknown-unknown/release/hello_uzumibi.wasm src/ && wrangler dev", |
| 99 | + "start": "wrangler dev", |
| 100 | + "test": "vitest" |
| 101 | + } |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +The `dev` script performs both the Rust build (WASM compilation) and Wrangler dev server startup in one step. |
| 106 | + |
| 107 | +## Installing Dependencies |
| 108 | + |
| 109 | +Navigate to the project directory and install the Node.js dependencies: |
| 110 | + |
| 111 | +```bash |
| 112 | +cd hello-uzumibi |
| 113 | +pnpm install |
| 114 | +``` |
| 115 | + |
| 116 | +This installs development tools including Wrangler locally within the project. |
0 commit comments