Deploy your own
If you like this architecture and want to deploy your own, this guide is for you! You mostly to deploy 3 things:
A tiny frontend api to deploy your bundle to.
A tiny frontend of your own to deploy to that api.
The
contract
npm package to publish to an npm registry to consume your tiny frontend at runtime.
WARNING
This section will make much more sense if you have read the Architecture one before!
Deploying the tiny frontend Cloudflare api
This is where your tiny frontend bundles will be deployed to.
If you don't have one already, setup a Cloudflare account.
Fork the tiny frontend api cloudflare repository on GitHub.
Enable GitHub actions for your forked repo under the
Actions
tab.Add two new secrets in your forked GitHub repository secrets:
CF_ACCOUNT_ID
you can find it in the workers section of your Cloudflare dashboard.CF_API_TOKEN
you can create one in your Cloudflare profile settings:- Select
Create Token
. - Next to
Edit Cloudflare Workers
clickUse template
. - Under
Account Resources
select the account you want to deploy the API to. - Under
Zone Resources
selectAll zones from an account
and the account you want to deploy the API to. - Continue to summary and finally click
Create Token
.
- Select
Clone your forked GitHub repository locally.
Create a KV namespace in Cloudflare to deploy your tiny frontends to, the name doesn't matter.
Edit
wrangler.toml
and set theTinyFrontendKv
id
value to theKV namespace
you've created above. (You can ignore thepreview_id
for now.)Commit and push your changes to
main
, this will trigger theDeploy Cloudflare Worker
GitHub action.
You should see the worker appear in your Cloudflare workers dashboard, along with its URL 🎉 .
Deploying the example tiny frontend
This is your actual tiny frontend you will deploy to the tiny frontend api above.
Setting up the repository
Fork the tiny frontend example repository on GitHub.
Enable GitHub actions for your forked repo under the
Actions
tab.Add three new secrets in your forked GitHub repository secrets:
CF_ACCOUNT_ID
you can find it in the workers section of your Cloudflare dashboard.CF_API_TOKEN
this can be the same as the one created for the tiny frontend Cloudflare api above. If you don't have it anymore, you can follow the same steps again to create a new one.CF_KV_NAMESPACE_TINY_FRONTEND
set it to the id of the KV namespace you created before.
- Clone your forked GitHub repository locally.
TIP
In the future, I'd like to have some kind of generator for this step instead of relying on forking the example.
Making changes to the tiny frontend
Sure, my example component is ✨ Amazing ✨, but you probably want something different. Let's see how to change things.
Running it locally
To let you work on your tiny frontend independently of any host, you can use the included vite dev server:
cd app
npm i
npm run dev
2
3
This starts a small dev server on http://localhost:3000 with app/index.html
and app/src/main.tsx
.
Changing the props
In contract/src/props.ts
, change ExampleTinyFrontendProps
to whichever props your component will need.
Then change the dev app in app/src/App.tsx
to pass the required props.
WARNING
Changing props is usually a breaking change.
If you have already published a version of your contract
, you should also update the version of your tiny frontend in contract/package.json
.
This will ensure your new app
with breaking changes doesn't get pulled by consumers of the current contract, who might not be compatible at runtime with your change.
Changing the implementation
In app/lib/index.tsx
, you can change the implementation of your component.
app
Deploying the Once you're happy with your frontend, simply commit and push. This should trigger the Deploy Tiny Frontend
GitHub action, and deploy your frontend to your tiny api for your contract
version.
contract
locally
Consuming the If you don't want to publish the contract
npm package to a npm repository to try it out, you can consume it locally using yalc.
First, "publish" your contract
on your machine:
cd contract
npm i
npm run build
npx yalc publish
2
3
4
TIP
This won't publish it online, only locally on your computer!
Create an example Remix app, or clone the example host remix one.
Install your local contract
package:
cd my-remix-app
npx yalc add @tiny-frontend/example-tiny-frontend-contract
npm i
2
3
You can now use your tiny frontend in your Remix app by pointing to your deployed tiny api:
// ⚠️ Notice the `/api` at the end of that URL!
loadExampleTinyFrontendClient("https://YOUR-CLOUDFLARE-WORKER.workers.dev/api")
2
contract
Publishing the The contract
can be deployed like any regular npm package.
The example tiny frontend include a Publish
GitHub action that publishes to the public npm repository when you create a GitHub release.
Checkout GitHub actions documentation on how to publish to other npm repositories.