Skip to content

Commit f13843f

Browse files
authored
section(www): Deployment - esbuild + gh deployment workflow (#11)
* bundle using esbuild * add rust build to gh-workflow
1 parent bbc420c commit f13843f

12 files changed

Lines changed: 3442 additions & 126 deletions

File tree

.github/workflows/gh-deploy.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
name: Build Connectors
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repo
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: 22
21+
22+
- name: Setup Rust
23+
uses: dtolnay/rust-toolchain@stable
24+
25+
- name: Install wasm-pack
26+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
27+
28+
- name: Build WASM binary
29+
run: |
30+
cd connecto.rs
31+
chmod +x build.sh
32+
./build.sh
33+
34+
- name: Install dependencies
35+
uses: bahmutov/npm-install@v1.10.9
36+
with:
37+
working-directory: ./www
38+
39+
- name: Build project
40+
run: npm run build
41+
working-directory: ./www
42+
43+
- name: Upload build files
44+
uses: actions/upload-artifact@v4
45+
with:
46+
name: artifacts
47+
path: ./www/dist
48+
49+
deploy:
50+
name: Deploy Connectors
51+
runs-on: ubuntu-latest
52+
permissions:
53+
contents: write
54+
steps:
55+
- uses: actions/checkout@v4
56+
57+
- name: Download build artifacts
58+
uses: actions/download-artifact@v4
59+
with:
60+
name: artifacts
61+
path: ./www/dist
62+
63+
- name: Deploy
64+
uses: peaceiris/actions-gh-pages@v4
65+
if: github.ref == 'refs/heads/main'
66+
with:
67+
github_token: ${{ secrets.GITHUB_TOKEN }}
68+
publish_dir: ./www/dist
69+
needs: build

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ connectors/
6464
- [5.2 - Adding interactivity](https://github.com/tauseefk/connectors/tree/interactivity)
6565
- Chapter 6
6666
- [Chapter 6 - Computing the winner](https://github.com/tauseefk/connectors/tree/winning-move)
67+
- Chapter 7
68+
- [Chapter 7 - Build and deploy]()
6769

6870
## Other Resources
6971

connecto.rs/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -euo pipefail
44

5-
TARGET=web
5+
TARGET=bundler
66
OUTDIR=../../www/connectors
77

88
wasm-pack build connectors --target $TARGET --release --out-dir $OUTDIR

www/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/connectors
2+
.DS_Store
3+
node_modules
4+
/dist

www/build.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import esbuild from "esbuild";
2+
import { copy } from "esbuild-plugin-copy";
3+
import { wasmLoader } from "esbuild-plugin-wasm";
4+
5+
const isDevelopment = process.env.NODE_ENV === "development";
6+
7+
const buildOptions = {
8+
logLevel: "info",
9+
entryPoints: ["src/index.js"],
10+
bundle: true,
11+
minify: !isDevelopment,
12+
format: "esm",
13+
platform: "browser",
14+
target: "es2022",
15+
outdir: "./dist",
16+
plugins: [
17+
wasmLoader(),
18+
// copy the index.html and styles.css as they are
19+
copy({
20+
resolveFrom: "cwd",
21+
assets: {
22+
from: ["./public/*"],
23+
to: ["./dist"],
24+
},
25+
}),
26+
],
27+
};
28+
29+
const run = async () => {
30+
try {
31+
const ctx = await esbuild.context(buildOptions);
32+
33+
if (!isDevelopment) {
34+
await esbuild.build(buildOptions);
35+
console.log("Build complete");
36+
37+
process.exit(0);
38+
return;
39+
}
40+
41+
// DEV server
42+
await ctx.serve({
43+
port: 8000,
44+
servedir: "./dist",
45+
});
46+
await ctx.watch();
47+
} catch (e) {
48+
console.error(e);
49+
process.exit(1);
50+
}
51+
};
52+
53+
run();

www/index.html

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)