chore: update ahead-of-time build docs for Deno Deploy (#2381)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
co-authored by
Marvin Hagemeister
parent
13d514dab8
commit
29d582c987
@@ -7,7 +7,7 @@ Fresh enables you to pre-optimize frontend assets before the code is deployed.
|
|||||||
During that process the code for Islands will be compressed and optimized, so
|
During that process the code for Islands will be compressed and optimized, so
|
||||||
that Fresh can send as little code as possible to the browser. Depending on the
|
that Fresh can send as little code as possible to the browser. Depending on the
|
||||||
amount of code an island needs, this process can take several seconds if done on
|
amount of code an island needs, this process can take several seconds if done on
|
||||||
the fly serverside.
|
the fly server-side.
|
||||||
|
|
||||||
Doing those optimizations ahead-of-time and deploying the already optimized
|
Doing those optimizations ahead-of-time and deploying the already optimized
|
||||||
assets alongside with your code, allows Fresh to treat them as like any other
|
assets alongside with your code, allows Fresh to treat them as like any other
|
||||||
@@ -16,7 +16,7 @@ pages with islands, having to do no processing greatly speeds up page load
|
|||||||
times.
|
times.
|
||||||
|
|
||||||
Plugins can build static assets during ahead-of-time builds. This can be used to
|
Plugins can build static assets during ahead-of-time builds. This can be used to
|
||||||
preprocess or generate CSS files, for example.
|
pre-process or generate CSS files, for example.
|
||||||
|
|
||||||
## Creating an optimized build
|
## Creating an optimized build
|
||||||
|
|
||||||
@@ -58,61 +58,14 @@ Using snapshot found at /path/to/project/_fresh
|
|||||||
|
|
||||||
## Deploying an optimized Fresh project
|
## Deploying an optimized Fresh project
|
||||||
|
|
||||||
To generate optimized assets whenever you push changes to the `main` branch of
|
If you are deploying a Fresh project to Deno Deploy, you can use ahead-of-time
|
||||||
your project, copy the following GitHub action and add it under
|
builds to optimize the assets before deploying them. This will make your
|
||||||
`.github/workflows/deploy.yml` in your project.
|
application load quicker.
|
||||||
|
|
||||||
```yml .github/workflows/deploy.yml
|
Open the Deno Deploy dashboard for your project and head to the "Git
|
||||||
name: Deploy
|
Integration" section in the project settings. Enter `deno task build` in the
|
||||||
on:
|
"Build command" field and save. This will switch your Deno Deploy project to use
|
||||||
push:
|
ahead-of-time builds.
|
||||||
branches: [main]
|
|
||||||
pull_request:
|
|
||||||
branches: main
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy:
|
|
||||||
name: Deploy
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
id-token: write # Needed for auth with Deno Deploy
|
|
||||||
contents: read # Needed to clone the repository
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Clone repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Install Deno
|
|
||||||
uses: denoland/setup-deno@v1
|
|
||||||
with:
|
|
||||||
deno-version: v1.x
|
|
||||||
|
|
||||||
- name: Build step
|
|
||||||
run: "deno task build" # 📝 Update the build command(s) if necessary
|
|
||||||
|
|
||||||
- name: Upload to Deno Deploy
|
|
||||||
uses: denoland/deployctl@v1
|
|
||||||
with:
|
|
||||||
project: "example-project" # 📝 Update the deploy project name if necessary
|
|
||||||
entrypoint: "./main.ts" # 📝 Update the entrypoint if necessary
|
|
||||||
```
|
|
||||||
|
|
||||||
> [info]: The project name here must match the project name you've picked in
|
|
||||||
> Deno Deploy under<br/> `Settings -> Project Name`.
|
|
||||||
|
|
||||||
On the Deno Deploy side change the GitHub integration mode to GitHub Actions.
|
|
||||||
You need to unlink first, if you have an existing project that's linked with the
|
|
||||||
"Automatic" mode.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
Once this is set up you're ready for your next deployment. Whenever a new PR is
|
|
||||||
merged into the `main` branch on GitHub the deploy action will be executed and
|
|
||||||
deploy the optimized assets to Deno Deploy.
|
|
||||||
|
|
||||||
> [info]: If the project is already linked in "Automatic" mode, unlink the
|
|
||||||
> repository first and re-link it again.
|
|
||||||
|
|
||||||
## Migrating existing projects with Plugins
|
## Migrating existing projects with Plugins
|
||||||
|
|
||||||
|
|||||||
@@ -17,11 +17,13 @@ the code needs to be pushed to a repository on GitHub. Once this has been done,
|
|||||||
one must go to the [Deno Deploy dashboard][deno-deploy-dashboard] and create a
|
one must go to the [Deno Deploy dashboard][deno-deploy-dashboard] and create a
|
||||||
new project.
|
new project.
|
||||||
|
|
||||||
After creating the project, head to the "Git" tab in the project settings,
|
Click on the "New Project" button and select the GitHub repository that contains
|
||||||
select the repository, the production branch (`main`) and the entrypoint file
|
the Fresh project. Select the "Fresh" framework preset, and click on "Advanced
|
||||||
(`main.ts`). This will link the project to the repository and automatically
|
options". Enter `deno task build` in the "Build command" field. Press "Create
|
||||||
deploy it to the internet. The project will now be available at
|
project".
|
||||||
https://$PROJECT_NAME.deno.dev.
|
|
||||||
|
The project will now deploy to Deno Deploy. After this is done, the project will
|
||||||
|
be available at https://$PROJECT_NAME.deno.dev.
|
||||||
|
|
||||||
Every time the code in the GitHub repository is updated, it will be deployed
|
Every time the code in the GitHub repository is updated, it will be deployed
|
||||||
either as a preview or production deployment. Production deployments are only
|
either as a preview or production deployment. Production deployments are only
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { basename, colors, join, parse, resolve } from "./src/dev/deps.ts";
|
|||||||
import { error } from "./src/dev/error.ts";
|
import { error } from "./src/dev/error.ts";
|
||||||
import { collect, ensureMinDenoVersion, generate } from "./src/dev/mod.ts";
|
import { collect, ensureMinDenoVersion, generate } from "./src/dev/mod.ts";
|
||||||
import {
|
import {
|
||||||
AOT_GH_ACTION,
|
|
||||||
dotenvImports,
|
dotenvImports,
|
||||||
freshImports,
|
freshImports,
|
||||||
tailwindImports,
|
tailwindImports,
|
||||||
@@ -340,12 +339,6 @@ if (useTailwind) {
|
|||||||
join(resolvedDirectory, "tailwind.config.ts"),
|
join(resolvedDirectory, "tailwind.config.ts"),
|
||||||
TAILWIND_CONFIG_TS,
|
TAILWIND_CONFIG_TS,
|
||||||
);
|
);
|
||||||
const ghWorkflowDir = join(resolvedDirectory, ".github", "workflows");
|
|
||||||
await Deno.mkdir(ghWorkflowDir, { recursive: true });
|
|
||||||
await Deno.writeTextFile(
|
|
||||||
join(ghWorkflowDir, "deploy.yml"),
|
|
||||||
AOT_GH_ACTION,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const TWIND_CONFIG_TS = `import { defineConfig, Preset } from "@twind/core";
|
const TWIND_CONFIG_TS = `import { defineConfig, Preset } from "@twind/core";
|
||||||
|
|||||||
@@ -37,38 +37,3 @@ export function tailwindImports(imports: Record<string, string>) {
|
|||||||
export function dotenvImports(imports: Record<string, string>) {
|
export function dotenvImports(imports: Record<string, string>) {
|
||||||
imports["$std/"] = `https://deno.land/std@${RECOMMENDED_STD_VERSION}/`;
|
imports["$std/"] = `https://deno.land/std@${RECOMMENDED_STD_VERSION}/`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AOT_GH_ACTION = `name: Deploy
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
pull_request:
|
|
||||||
branches: main
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy:
|
|
||||||
name: Deploy
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
id-token: write # Needed for auth with Deno Deploy
|
|
||||||
contents: read # Needed to clone the repository
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Clone repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Install Deno
|
|
||||||
uses: denoland/setup-deno@v1
|
|
||||||
with:
|
|
||||||
deno-version: v1.x
|
|
||||||
|
|
||||||
- name: Build step
|
|
||||||
run: "deno task build" # 📝 Update the build command(s) if necessary
|
|
||||||
|
|
||||||
- name: Upload to Deno Deploy
|
|
||||||
uses: denoland/deployctl@v1
|
|
||||||
with:
|
|
||||||
project: "example-project" # 📝 Update the deploy project name if necessary
|
|
||||||
entrypoint: "./main.ts" # 📝 Update the entrypoint if necessary
|
|
||||||
`;
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import { AOT_GH_ACTION } from "../dev/imports.ts";
|
|
||||||
|
|
||||||
const LINK = "https://fresh.deno.dev/docs/concepts/ahead-of-time-builds";
|
const LINK = "https://fresh.deno.dev/docs/concepts/ahead-of-time-builds";
|
||||||
|
|
||||||
export default function TailwindErrorPage() {
|
export default function TailwindErrorPage() {
|
||||||
@@ -18,63 +16,18 @@ export default function TailwindErrorPage() {
|
|||||||
<code>Settings</code> tab.
|
<code>Settings</code> tab.
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
Set Git-Integration to <code>GitHub Action</code>.<br />
|
In the Git Integration section, enter <code>deno task build</code>
|
||||||
<i style="display: block; font-style: italic; color: gray;">
|
|
||||||
Unlink the repository first if it is already linked via{" "}
|
|
||||||
<code>Automatic</code> and re-link it again.
|
|
||||||
</i>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
Add the file <code>.github/workflows/deploy.yml</code>{" "}
|
|
||||||
to your repository with the following contents:<br />
|
|
||||||
<span style="background: #f0f0f0;display: block; position: relative;">
|
|
||||||
<button
|
|
||||||
id="copy-gh-action"
|
|
||||||
style="position: absolute; top: .5rem; right: .5rem;z-index: 100"
|
|
||||||
>
|
|
||||||
copy code
|
|
||||||
</button>
|
|
||||||
<pre style="height: 200px; overflow: auto;padding: 1rem;"><code>{AOT_GH_ACTION}</code></pre>
|
|
||||||
</span>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
Copy the project name under <code>Setting {">"} Project Name</code>
|
|
||||||
{" "}
|
{" "}
|
||||||
and replace "example project" with your actual project name in{" "}
|
in the <code>Build Command</code> input.
|
||||||
<code>.github/workflows/deploy.yml</code>.
|
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
Commit the file you created and merge it into the <code>main</code>
|
Save the changes.
|
||||||
{" "}
|
|
||||||
branch. This will trigger a new deployment and finish the setup.
|
|
||||||
</li>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
<p>
|
<p>
|
||||||
See the detailed guide here: <a href={LINK}>{LINK}</a>.
|
See the detailed guide here: <a href={LINK}>{LINK}</a>.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<script
|
|
||||||
dangerouslySetInnerHTML={{
|
|
||||||
__html: `
|
|
||||||
const copyBtn = document.querySelector("#copy-gh-action");
|
|
||||||
if (copyBtn) {
|
|
||||||
let timeout;
|
|
||||||
const text = copyBtn.textContent;
|
|
||||||
copyBtn.addEventListener("click", async () => {
|
|
||||||
copyBtn.textContent = "copied!";
|
|
||||||
|
|
||||||
clearTimeout(timeout);
|
|
||||||
timeout = setTimeout(() => {
|
|
||||||
copyBtn.textContent = text
|
|
||||||
}, 2000);
|
|
||||||
|
|
||||||
const code = \`${AOT_GH_ACTION}\`;
|
|
||||||
await navigator.clipboard.writeText(code);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
`,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,7 +185,6 @@ Deno.test({
|
|||||||
"/.vscode/settings.json",
|
"/.vscode/settings.json",
|
||||||
"/.vscode/extensions.json",
|
"/.vscode/extensions.json",
|
||||||
"/.gitignore",
|
"/.gitignore",
|
||||||
"/.github/workflows/deploy.yml",
|
|
||||||
];
|
];
|
||||||
|
|
||||||
await t.step("check generated files", async () => {
|
await t.step("check generated files", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user