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
You can host your built Framework app on any static site hosting service, or self-host it with any static site server. This guide covers deploying to [Observable Cloud](https://observablehq.com/platform/cloud), which is the easiest way to host your Framework app as support is built-in. We’ll also cover setting up automated deploys with GitHub Actions.
3
+
You can host your built Framework app on any static site hosting service, or self-host it with any static site server. This guide covers automating deploys to [GitHub Pages](https://pages.github.com/) with [GitHub Actions](https://github.com/features/actions), and assumes that you are hosting your Framework project’s git repository on GitHub.
4
4
5
5
<divclass="tip">
6
6
7
7
If you don’t yet have an app ready to deploy, create one by following our [Getting started guide](./getting-started).
8
8
9
9
</div>
10
10
11
-
## Manual deploys
12
-
13
-
To deploy your app, run the deploy command:
14
-
15
-
```sh
16
-
npm run deploy
17
-
```
18
-
19
-
<divclass="tip">
20
-
21
-
Deploying automatically creates a [deploy configuration file](#deploy-configuration) (`.observablehq/deploy.json`) if it does not already exist. You should commit this file to git; it is required for automated deploys, and lets you re-deploy manually with fewer prompts.
22
-
23
-
</div>
24
-
25
-
The first time you deploy an app, you will be prompted to configure the app’s _slug_ (which determines its URL), access level, and other details. If you aren’t yet signed-in to Observable, you will also be prompted to sign-in.
26
-
27
-
When the deploy command finishes, it prints a link to observablehq.cloud where you can view your deployed app. If you choose _private_ as the access level, that link will only be accessible to members of your Observable workspace. (You can invite people to your workspace by going to observablehq.com.) If you choose _public_, you can share your app link with anyone. You can change the access level of an app later [from your Data apps page](https://observablehq.com/select-workspace?next=projects).
28
-
29
-
<divclass="tip">
30
-
31
-
To see more available options when deploying:
32
-
33
-
```sh run=false
34
-
npm run deploy -- --help
35
-
```
36
-
37
-
</div>
38
-
39
-
## Automated deploys
40
-
41
-
After deploying an app manually at least once, Observable can handle subsequent deploys for you automatically. You can automate deploys both [on commit](https://observablehq.com/documentation/data-apps/github) (whenever you push a new commit to your project’s default branch) and [on schedule](https://observablehq.com/documentation/data-apps/schedules) (such as daily or weekly).
42
-
43
-
Automatic deploys — also called _continuous deployment_ or _CD_ — ensure that your data is always up to date, and that any changes you make to your app are immediately reflected in the deployed version.
44
-
45
-
On your app settings page on Observable, open the **Build settings** tab to set up a link to a GitHub repository hosting your project’s files. Observable will then listen for changes in the repo and deploy the app automatically.
46
-
47
-
The settings page also allows you to trigger a manual deploy on Observable Cloud, add secrets (for data loaders to use private APIs and passwords), view logs, configure sharing, _etc._ For details, see the [Building & deploying](https://observablehq.com/documentation/data-apps/deploys) documentation.
48
-
49
-
## GitHub Actions
50
-
51
-
As an alternative to building on Observable Cloud, you can use [GitHub Actions](https://github.com/features/actions) and have GitHub build a new version of your app and deploy it to Observable. In your git repository, create and commit a file at `.github/workflows/deploy.yml`. Here is a starting example:
11
+
In your git repository, create the file `.github/workflows/deploy.yml` with the following contents:
52
12
53
13
```yaml
54
14
name: Deploy
@@ -64,59 +24,37 @@ on:
64
24
jobs:
65
25
deploy:
66
26
runs-on: ubuntu-latest
27
+
permissions:
28
+
contents: read
29
+
pages: write
30
+
id-token: write
31
+
environment:
32
+
name: github-pages
33
+
url: ${{ steps.deployment.outputs.page_url }}
67
34
steps:
68
35
- uses: actions/checkout@v4
69
36
- uses: actions/setup-node@v4
70
37
with:
71
-
node-version: 20
38
+
node-version: 22
72
39
cache: npm
73
40
- run: npm ci
74
41
- run: npm run build
75
-
- name: Deploy to Observable Cloud
76
-
# This parameter to `--message` will use the latest commit message
77
-
run: npm run deploy -- --message "$(git log -1 --pretty=%s)"
78
-
env:
79
-
# Authentication information. See below for how to set this up.
80
-
OBSERVABLE_TOKEN: ${{ secrets.OBSERVABLE_TOKEN }}
42
+
- uses: actions/configure-pages@v4
43
+
- uses: actions/upload-pages-artifact@v3
44
+
with:
45
+
path: dist
46
+
- name: Deploy
47
+
id: deployment
48
+
uses: actions/deploy-pages@v4
81
49
```
82
50
83
-
<div class="tip">As shown above, deploy messages can be set using <code>--message</code>. This is especially useful for continuous deployment from a git repository: the message can include the SHA, author, and message of the latest commit.</div>
84
-
85
-
When deploying automatically, you can’t sign-in in your browser the way you did for manual deploys; instead, your GitHub action will authenticate using an Observable API key (also known as a _token_ and referred to as `OBSERVABLE_TOKEN` above).
86
-
87
-
To create an API key:
88
-
89
-
1. Open the [API Key settings](https://observablehq.com/select-workspace?next=api-keys-settings) for your Observable workspace.
90
-
2. Click **New API Key**.
91
-
3. Check the **Deploy new versions of projects** checkbox. <!-- TODO apps -->
92
-
4. Give your key a description, such as “Deploy via GitHub Actions”.
93
-
5. Click **Create API Key**.
94
-
95
-
<div class="caution">
96
-
97
-
The token you create is the equivalent of a password giving write access to your hosted app. **Do not commit it to git** or share it with anyone you don’t trust. If you accidentally expose your key, you can go back to your settings to immediately revoke it (and create a new key).
98
-
99
-
</div>
100
-
101
-
In a moment, you’ll copy-paste your new Observable API key, so leave this window open for now. (If you accidentally close the window, you can delete the old key and create a new one. For security, API keys are only shown once upon creation.)
102
-
103
-
To authenticate with Observable and to access the Observable API key securely from our Github action, we’ll use a [GitHub secret](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions).
104
-
105
-
To create a GitHub secret, in a new window:
51
+
Commit this file to your main branch and push to GitHub. Then follow [GitHub’s instructions](https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#publishing-with-a-custom-github-actions-workflow) to specify GitHub Actions as the source for GitHub Pages.
106
52
107
-
1. Go to your GitHub repository.
108
-
2. In the top navigation, click **Settings**.
109
-
3. In the left sidebar, click **Secrets and variables**, then **Actions**.
110
-
4. Click **New repository secret**.
111
-
5. In the **Name** field, enter `OBSERVABLE_TOKEN`.
112
-
6. In the **Secret** field, paste the API key you created on Observable.
113
-
7. Click **Add secret**.
114
-
115
-
After you’ve performed these steps, the `deploy.yml` above will automatically build and deploy your app once per day (to keep your data up-to-date), as well as whenever you push a new version of the code to your repository (so you can make changes at any time).
53
+
After you’ve performed these steps, the `deploy.yml` above will automatically build and deploy your app once per day (to keep your data up-to-date), as well as whenever you push new commits to your GitHub repository’s main branch (so you can make changes at any time). You will also be able to manually trigger a deploy through GitHub’s user interface. If you like, you can disable any of these triggers (`push`, `schedule`, or `workflow_dispatch`) by updating the `deploy.yml` file.
116
54
117
55
### Caching
118
56
119
-
If some of your data loaders take a long time to run, or simply don’t need to be updated every time you modify the code, you can set up caching to automatically re-use existing data from previous builds. To do that, add the following steps to your `deploy.yml` before you run `build`:
57
+
If some of your data loaders take a long time to run, or simply don’t need to be updated every time you build, you can set up caching to automatically re-use existing data from previous builds. To do that, add the following steps to your `deploy.yml` before `npm run build`:
120
58
121
59
```yaml
122
60
jobs:
@@ -133,28 +71,10 @@ jobs:
133
71
# …
134
72
```
135
73
136
-
This uses one cache per calendar day (in the `America/Los_Angeles` time zone). If you deploy multiple times in a day, the results of your data loaders will be reused on the second and subsequent runs. You can customize the `date` and `cache-data` steps to change the cadence of the caching. For example you could use `date +'%Y-%U'` to cache data for a week or `date +'%Y-%m-%dT%H'` to cache it for only an hour.
137
-
138
-
<div class="note">You’ll need to edit the paths above if you’ve configured a source root other than <code>src</code>.</div>
74
+
<div class="note">
139
75
140
-
## Deploy configuration
76
+
This will only cache data loaders that live under <code>src/data</code>. You’ll need to edit the paths above if you’ve configured a source root other than <code>src</code>, or if the data loaders you want to cache live elsewhere.
141
77
142
-
The deploy command creates a file at <code>.observablehq/deploy.json</code> under the source root (typically <code>src</code>) with information on where to deploy the app. This file allows you to re-deploy an app without having to repeat where you want the app to live on Observable.
143
-
144
-
The contents of the deploy config file look like this:
145
-
146
-
```json run=false
147
-
{
148
-
"projectId": "0123456789abcdef",
149
-
"projectSlug": "hello-framework",
150
-
"workspaceLogin": "acme"
151
-
}
152
-
```
153
-
154
-
To store the deploy config file somewhere else, use the `--deploy-config` argument. For example, to create a “staging” deploy to share early versions of your app, you could use a `deploy-staging.json` like so:
155
-
156
-
```sh
157
-
npm run deploy -- --deploy-config=src/.observablehq/deploy-staging.json
158
-
```
78
+
</div>
159
79
160
-
If the specified config file does not yet exist, you will again be prompted to choose or create a new app; the resulting configuration will then be saved to the specified file. You can re-deploy to staging by passing the same `--deploy-config` argument; or you can deploy to “production” by not specifying the `--deploy-config` argument to use the default deploy config.
80
+
This uses one cache per calendar day (in the `America/Los_Angeles` time zone). If you deploy multiple times in a day, the results of your data loaders will be reused on the second and subsequent runs. You can customize the `date` and `cache-data` steps to change the cadence of the caching. For example you could use `date +'%Y-%U'` to cache data for a week or `date +'%Y-%m-%dT%H'` to cache it for only an hour.
Copy file name to clipboardExpand all lines: docs/embeds.md
+4-6Lines changed: 4 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,8 +10,6 @@ In addition to standalone apps, you can use Framework to embed interactive views
10
10
-[exported files](#exported-files) for hotlinking images, data, and other assets, or
11
11
-[iframe embeds](#iframe-embeds) for compatibility.
12
12
13
-
You can deploy to Observable Cloud for [additional features](https://observablehq.com/documentation/data-apps/embeds)<ahref="https://github.com/observablehq/framework/releases/tag/v1.13.0"class="observablehq-version-badge"data-version="^1.13.0"title="Added in v1.13.0"></a> including secure private embedding on approved domains and analytics to see which exports are used.
14
-
15
13
## Exported modules
16
14
17
15
Framework allows [JavaScript modules](./imports#local-imports) to be exported for use in another application. Exported modules are vanilla JavaScript and behave identically in an external web application as on a Framework page. As with local modules, exported modules can load data from a [static file](./files) or a [data loader](./data-loaders), [import](./imports) other local modules, and import libraries from [npm](./imports#npm-imports) or [JSR](./imports#jsr-imports).
@@ -70,7 +68,7 @@ An exported module can then be imported into a vanilla web application like so:
Observable Cloud supports [cross-origin resource sharing](https://observablehq.com/documentation/data-apps/embeds#cors) (CORS), which is needed for exported modules.
80
+
You must [enable cross-origin resource sharing](https://enable-cors.org/) (CORS) on your hosting provider to import exported modules across domains.
With a little bit of additional JavaScript, you can also implement [responsive iframe embeds](https://observablehq.observablehq.cloud/framework-example-responsive-iframe/) which resize automatically to fit the content of the page.
Copy file name to clipboardExpand all lines: docs/getting-started.md
+5-48Lines changed: 5 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,7 +74,7 @@ const digraph = dot`digraph {
74
74
${digraph}
75
75
</figure>
76
76
77
-
First you’ll setup your local development environment by [**creating**](#1-create) a new project. A project contains all the source code needed to build an app. Next you’ll [**develop**](#2-develop): an iterative process where you save changes to source files in your editor while previewing the result in your browser. When you’re ready to share, it’s time to [**publish**](#3-publish): you can either build a static site for self-hosting or deploy directly to Observable. Lastly, you can invite people to view your app!
77
+
First you’ll setup your local development environment by [**creating**](#1-create) a new project. A project contains all the source code needed to build an app. Next you’ll [**develop**](#2-develop): an iterative process where you save changes to source files in your editor while previewing the result in your browser. When you’re ready to share, it’s time to [**publish**](#3-publish): you build and deploy your static site to your preferred hosting provider.
78
78
79
79
These are just first steps. You can continue to develop apps after publishing, and republish as needed. You can also setup continuous deployment to publish your app automatically on commit or on schedule. We’ll cover these [next steps](#next-steps) briefly below.
80
80
@@ -476,52 +476,7 @@ _Ta-da!_ 🎉 Perhaps not the most exciting dashboard yet, but it has potential!
476
476
477
477
## 3. Publish
478
478
479
-
When you’re ready to share your app — either privately or publicly — you can quickly deploy it to [Observable](https://observablehq.com) using the `deploy` command:
480
-
481
-
<predata-copy>npm run deploy</pre>
482
-
483
-
Or with Yarn:
484
-
485
-
<predata-copy>yarn deploy</pre>
486
-
487
-
<divclass="note">If you don’t have an Observable account yet, you will be prompted to sign up. Observable is free for individuals and small teams, and we offer paid tiers for larger teams.</div>
488
-
489
-
This command will ask you a few questions to configure your deploy, including which Observable workspace to use and whether the app should be public or private. You can also enter an optional message to associate with the deploy, but for now feel free to leave this blank by hitting Enter.
490
-
491
-
When deploy completes, Framework will show your app’s URL on observablehq.cloud, like below. From there you can invite people to your private workspace to see your app, or make your app public so anyone can see it.
<spanclass="blue">●</span> To configure deploy, we need to ask you a few questions.
497
-
<spanclass="muted">│</span>
498
-
<spanclass="green">◇</span> Which Observable workspace do you want to use?
499
-
<spanclass="muted">│ Example Inc. (@example)</span>
500
-
<spanclass="muted">│</span>
501
-
<spanclass="green">◇</span> Which app do you want to use?
502
-
<spanclass="muted">│ Create a new app</span>
503
-
<spanclass="muted">│</span>
504
-
<spanclass="green">◇</span> What slug do you want to use?
505
-
<spanclass="muted">│ hello-framework</span>
506
-
<spanclass="muted">│</span>
507
-
<spanclass="green">◇</span> Who is allowed to access your app?
508
-
<spanclass="muted">│ Private</span>
509
-
<spanclass="muted">│</span>
510
-
<spanclass="green">◇</span> What changed in this deploy?
511
-
<spanclass="muted">│</span> <spanclass="muted">Enter a deploy message (optional)</span>
512
-
<spanclass="muted">│</span>
513
-
<spanclass="green">◇</span> 18 uploaded
514
-
<spanclass="muted">│</span>
515
-
<spanclass="green">◇</span> Deploy complete
516
-
<spanclass="muted">│</span>
517
-
<spanclass="muted">└</span> <spanclass="muted">Deployed app now visible at <u>https://example.observablehq.cloud/hello-framework/</u></span>
518
-
</pre>
519
-
520
-
<divclass="tip">Your deploy configuration is saved to <code>src<spanclass="wbr">/</span>.observablehq<spanclass="wbr">/</span>deploy.json</code>. When collaborating on an app, you should commit this file to git so your collaborators don’t have to separately configure deploy.</div>
521
-
522
-
### Self hosting
523
-
524
-
Of course, you don’t have to deploy to Observable — Framework apps are simply static sites, so you can host them anywhere!
479
+
When you’re ready to share your app, you can quickly build and deploy it to your preferred hosting provider, such as GitHub Pages.
525
480
526
481
To build your app with npm, run:
527
482
@@ -531,7 +486,7 @@ Or with Yarn:
531
486
532
487
<predata-copy>yarn build</pre>
533
488
534
-
The <code>build</code> command generates the `dist` directory; you can then copy this directory to your static site server or preferred hosting service. To preview your built app locally, you can use a local static HTTP server such as [http-server](https://github.com/http-party/http-server):
489
+
The <code>build</code> command generates the `dist` directory; you can then upload this directory to your preferred hosting provider or copy it to your static site server for self-hosting. To preview your built app locally, you can use a local static HTTP server such as [http-server](https://github.com/http-party/http-server):
535
490
536
491
<predata-copy>npx http-server dist</pre>
537
492
@@ -541,6 +496,8 @@ The <code>build</code> command generates the `dist` directory; you can then copy
541
496
<ahref="https://github.com/actions/deploy-pages">deploy-pages</a>, and
542
497
<ahref="https://github.com/actions/upload-pages-artifact">upload-pages-artifact</a>), you may need to create a <code>.nojekyll</code> file in your <code>dist</code> folder after building. See GitHub’s documentation on <ahref="https://docs.github.com/en/pages/getting-started-with-github-pages/about-github-pages#static-site-generators">static site generators</a> for more.</div>
543
498
499
+
To deploy your app to GitHub Pages using GitHub Actions, read our [Deploying guide](./deploying).
0 commit comments