You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/workers/frameworks/framework-guides/remix.mdx
+209-4Lines changed: 209 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,9 +13,11 @@ import {
13
13
PackageManagers,
14
14
} from"~/components";
15
15
16
-
In this guide, you will create a new[Remix](https://remix.run/) application and deploy to Cloudflare Workers (with the new [<InlineBadgepreset="beta" /> Workers Assets](/workers/static-assets/)).
16
+
In this guide, you can [create a new](/workers/frameworks/framework-guides/remix/#create-a-new-application) or [deploy an existing](/workers/frameworks/framework-guides/remix/#deploy-an-existing-remix-application)[Remix](https://remix.run/) application to Cloudflare Workers with the new [<InlineBadgepreset="beta" /> Workers Assets](/workers/static-assets/) feature.
17
17
18
-
## 1. Set up a new project
18
+
## Create a new application
19
+
20
+
### 1. Set up a new project
19
21
20
22
Use the [`create-cloudflare`](https://www.npmjs.com/package/create-cloudflare) CLI (C3) to set up a new project. C3 will create a new project directory, initiate Remix's official setup tool, and provide the option to deploy instantly.
21
23
@@ -42,13 +44,216 @@ After setting up your project, change your directory by running the following co
42
44
cd my-remix-app
43
45
```
44
46
45
-
## 2. Develop locally
47
+
### 2. Develop locally
48
+
49
+
After you have created your project, run the following command in the project directory to start a local server. This will allow you to preview your project locally during development.
50
+
51
+
<PackageManagerstype="run"args={"dev"} />
52
+
53
+
### 3. Deploy your Project
54
+
55
+
Your project can be deployed to a `*.workers.dev` subdomain or a [Custom Domain](/workers/configuration/routing/custom-domains/), from your own machine or from any CI/CD system, including [Cloudflare's own](/workers/ci-cd/builds/).
56
+
57
+
The following command will build and deploy your project. If you're using CI, ensure you update your ["deploy command"](/workers/ci-cd/builds/configuration/#build-settings) configuration appropriately.
58
+
59
+
<PackageManagerstype="run"args={"deploy"} />
60
+
61
+
---
62
+
63
+
## Deploy an existing Remix application
64
+
65
+
Deploy an existing Remix application (for example, if you created an application with the [create-remix CLI](https://remix.run/docs/en/main/other-api/create-remix)) to Cloudflare Workers.
66
+
67
+
### 1. Manage dependencies
68
+
69
+
a. Install [Cloudflare's Wrangler CLI tool](/workers/wrangler/) and [`@cloudflare/workers-types`](/@cloudflare/workers-types).
a. Remove the existing entry files that are tailored for Node.js.
90
+
91
+
```sh
92
+
rm -rf ./app/entry.*.tsx
93
+
```
94
+
95
+
b. Regenerate entry files compatible with Cloudflare.
96
+
97
+
```sh
98
+
npx remix reveal
99
+
```
100
+
101
+
### 3. Create `server.ts`
102
+
103
+
Create a `server.ts` file in the root directory. This file configures Remix for the Workers runtime and allows you to interact with Cloudflare-specific features like [`ctx`](/workers/runtime-apis/context/) and [Workers bindings](/workers/runtime-apis/bindings/).
Update the `./app/root.tsx` and `./app/routes/_index.tsx` files, by changing imports from `@remix-run/node` to `@remix-run/cloudflare`:
180
+
181
+
```js
182
+
import { ... } from"@remix-run/cloudflare";
183
+
```
184
+
185
+
### 8. Create `remix.config.js`
186
+
187
+
Create a `remix.config.js` file in the root directory. This file to defines various settings for how your application is built and behaves during development and deployment.
188
+
189
+
:::note
190
+
191
+
This uses the "Classic" Remix compiler, since Vite does not work with all Workers resources yet (for example, [Durable Objects](/durable-objects/), [Hyperdrive](/hyperdrive/), etc). We are currently working on supporting the Vite Environment for workerd. Once complete, this guide will be updated. Using Vite will not require any changes in your actual code, simply in configuration (for example `remix.config.js` will get replaced by `vite.config.js`).
Update `package.json` scripts to add wrangler commands and remove Vite.
240
+
241
+
```json
242
+
"scripts": {
243
+
"build": "remix build",
244
+
"dev": "remix dev --manual -c \"wrangler dev\"",
245
+
"deploy": "npm run build && wrangler deploy",
246
+
// ...other scripts
247
+
},
248
+
```
249
+
250
+
### 9. Develop locally
46
251
47
252
After you have created your project, run the following command in the project directory to start a local server. This will allow you to preview your project locally during development.
48
253
49
254
<PackageManagerstype="run"args={"dev"} />
50
255
51
-
##3. Deploy your Project
256
+
### 10. Deploy your Project
52
257
53
258
Your project can be deployed to a `*.workers.dev` subdomain or a [Custom Domain](/workers/configuration/routing/custom-domains/), from your own machine or from any CI/CD system, including [Cloudflare's own](/workers/ci-cd/builds/).
0 commit comments