+ Edit src/App.tsx and save to test HMR
+
+ Edit api/index.ts to change the name
+
+ Click on the Vite and React logos to learn more +
+ > + ); +} + +export default App; +``` + +Now, if you click the button, it will display 'Name from API is: Cloudflare'. + +Increment the counter to update the application state in the browser. +Next, edit `api/index.ts` by changing the `name` it returns to `'Cloudflare Workers'`. +If you click the button again, it will display the new `name` while preserving the previously set counter value. + +With Vite and the Cloudflare plugin, you can iterate on the client and server parts of your app together, without losing UI state between edits. + +### Build your application + +Run `npm run build` to build your application. + +```sh +npm run build +``` + +If you inspect the `dist` directory, you will see that it contains two subdirectories: + +- `client` - the client code that runs in the browser +- `cloudflare-vite-tutorial` - the Worker code alongside the output `wrangler.json` configuration file + +### Preview your application + +Run `npm run preview` to validate that your application runs as expected. + +```sh +npm run preview +``` + +This command will run your build output locally in the Workers runtime, closely matching its behaviour in production. + +### Deploy to Cloudflare + +Run `npm exec wrangler deploy` to deploy your application to Cloudflare. + +```sh +npm exec wrangler deploy +``` + +This command will automatically use the output `wrangler.json` that was included in the build output. + +## Next steps + +In this tutorial, we created an SPA that could be deployed as a Worker with static assets. +We then added an API Worker that could be accessed from the front-end code. +Finally, we deployed both the client and server-side parts of the application to Cloudflare. + +Possible next steps include: + +- Adding a binding to another Cloudflare service such as a [KV namespace](/kv/) or [D1 database](/d1/) +- Expanding the API to include additional routes +- Using a library, such as [Hono](https://hono.dev/) or [tRPC](https://trpc.io/), in your API Worker