-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/crewdevio/Snel
- Loading branch information
Showing
1 changed file
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -322,6 +322,157 @@ this syntax can be used in javascript, typescript files and components. | |
|
||
> **note**: you can change the behavior by rewriting the pattern inside the import_map.json file, although be careful when doing this. | ||
## Deploy SPA app | ||
|
||
If you want to have a simple workflow to deploy your SPA application, you can use this. | ||
|
||
`deploy` | ||
|
||
```yml | ||
name: Build and Deploy | ||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
build: | ||
runs-on: windows-latest | ||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/[email protected] | ||
|
||
- name: Install Deno | ||
uses: denolib/setup-deno@v2 | ||
with: | ||
deno-version: v1.x | ||
|
||
- name: Build | ||
run: | | ||
deno run --allow-run --allow-read https://deno.land/x/snel/install.ts | ||
trex run build | ||
- name: Upload Artifacts 🔺 | ||
uses: actions/upload-artifact@v1 | ||
with: | ||
name: site | ||
path: dist | ||
|
||
deploy: | ||
needs: [build] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/[email protected] | ||
|
||
- name: Download Artifacts 🔻 | ||
uses: actions/download-artifact@v1 | ||
with: | ||
name: site | ||
|
||
- name: Deploy 🚀 | ||
uses: JamesIves/[email protected] | ||
with: | ||
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} | ||
branch: deploy | ||
folder: "site" | ||
clean-exclude: | | ||
vercel.json | ||
manifest.json | ||
``` | ||
this compiles the application every time it is pushed to the `main` branch, and uploads the compiled files to the `deploy` branch, which could be deployed in hosts such as `vercel` or `netlify`. | ||
|
||
If you are using the snel client router and you are going to deploy vercel or netlify you must add the respective configuration files to avoid having 404 errors. | ||
|
||
`for vercel: vercel.json` | ||
|
||
```json | ||
{ | ||
"routes": [ | ||
{ "handle": "filesystem" }, | ||
{ "src": "/.*", "dest": "/index.html" } | ||
] | ||
} | ||
``` | ||
|
||
`for netlify: _redirects` | ||
|
||
```console | ||
/* /index.html 200 | ||
``` | ||
|
||
to avoid this files was removed in each deploy, you can ignore specific files: | ||
|
||
```yml | ||
.... | ||
- name: Deploy 🚀 | ||
uses: JamesIves/[email protected] | ||
with: | ||
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} | ||
branch: deploy | ||
folder: "site" | ||
clean-exclude: | | ||
vercel.json # <- ignore vercel.json and manifest.json file | ||
manifest.json | ||
``` | ||
|
||
for github pages you can use this trick: | ||
|
||
create a `404.html` file: | ||
|
||
```html | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>....</title> | ||
<script> | ||
sessionStorage.redirect = location.href; | ||
</script> | ||
<meta http-equiv="refresh" content="0;URL='/sghpa'"></meta> | ||
</head> | ||
<body> | ||
| ||
| ||
| ||
</body> | ||
</html> | ||
``` | ||
|
||
and in your `index.html` add this: | ||
|
||
|
||
```html | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>....</title> | ||
<style type="text/css"> | ||
body:before { | ||
content: attr(message); | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
..... | ||
<script> | ||
(() => { | ||
const redirect = sessionStorage.redirect; | ||
delete sessionStorage.redirect; | ||
if (redirect && redirect !== location.href) { | ||
history.replaceState(null, null, redirect); | ||
// REMOVE THIS - just showing the redirect route in the UI | ||
document.body.setAttribute('message', 'This page was redirected by 404.html, from the route: ' + redirect); | ||
} else { | ||
// REMOVE THIS - just showing the redirect route in the UI | ||
document.body.setAttribute('message', 'This page was loaded directly from the index.html file'); | ||
} | ||
})(); | ||
</script> | ||
</body> | ||
</html> | ||
``` | ||
|
||
## Hot Reloading | ||
|
||
Snel provides hot reload capability, it compiles and updates the application when changes are applied to it | ||
|