Skip to content

Commit

Permalink
Add Vanilla Rust example (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-peterson authored May 17, 2021
1 parent d1f84f4 commit 7126872
Show file tree
Hide file tree
Showing 17 changed files with 315 additions and 25 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ jobs:
restore-keys: |
wasm32-example-seed-debug-
- name: Setup | Cache Examples
uses: actions/cache@v2
with:
path: examples/vanilla/target
key: wasm32-example-vanilla-debug-${{ hashFiles('examples/vanilla/Cargo.lock') }}
restore-keys: |
wasm32-example-vanilla-debug-
- name: Setup | Rust
uses: actions-rs/toolchain@v1
with:
Expand All @@ -131,8 +139,10 @@ jobs:

# Build examples via our newly built debug artifact.
- name: Setup | wasm-bindgen
run: cargo install wasm-bindgen-cli --version 0.2.70
run: cargo install wasm-bindgen-cli --version 0.2.73
- name: Build | Examples
run: ${{ matrix.binPath }} --config=examples/yew/Trunk.toml build
- name: Build | Examples
run: ${{ matrix.binPath }} --config=examples/seed/Trunk.toml build
- name: Build | Examples
run: ${{ matrix.binPath }} --config=examples/vanilla/Trunk.toml build
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ This changelog follows the patterns described here: https://keepachangelog.com/e
Subheadings to categorize changes are `added, changed, deprecated, removed, fixed, security`.

## Unreleased
- Added an example application for using Trunk with a vanilla (no frameworks) Rust application.

## 0.11.0
### added
- Closed [#158](https://github.com/thedodd/trunk/issues/158): Support for inlining SASS/SCSS after compilation using the new `data-inline` attribute.
- Closed [#145](https://github.com/thedodd/trunk/issues/145): Preloading of the WASM and JS files are now added to the `<head>` element. This ensures that the code starts downloading as soon as possible, and can make your app start up a few seconds earlier on a slow network.
- Closed [#135](https://github.com/thedodd/trunk/pull/135): Allow users to specify `data-keep-debug` & `data-no-mangle` options on Rust build pipelines, which influence their corresponding `wasm-bindgen` CLI options.
- Added an example application for using Trunk with a vanilla (no frameworks) Rust application.

### fixed
- Fixed [#148](https://github.com/thedodd/trunk/issues/148): any changes detected under a `.git` path are now being ignored by default.
Expand Down
31 changes: 17 additions & 14 deletions examples/seed/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/seed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ serde = "1.0"
uuid = { version = "0.8.2", features = ["serde", "v4", "wasm-bindgen"] }
indexmap = { version = "1.6.1", features = ["serde-1"] }
enclose = "1.1.8"
wasm-bindgen = "=0.2.73" # This is pinned primarily for CI stability.
210 changes: 210 additions & 0 deletions examples/vanilla/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/vanilla/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "vanilla-example"
version = "0.1.0"
authors = ["Philip Peterson <[email protected]>"]
edition = "2018"

[dependencies]
console_error_panic_hook = "0.1.6"
web-sys = { version = "0.3.49", features = ["Window", "Document", "HtmlElement", "Node", "Text"] }
wasm-bindgen = "=0.2.73" # This is pinned primarily for CI stability.
wee_alloc = "0.4.5"
7 changes: 7 additions & 0 deletions examples/vanilla/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
trunk | vanilla | web-sys
==========================
An example application demonstrating building a vanilla Rust (no frameworks) WASM web application using web-sys.

Once you've installed Trunk, simply execute `trunk serve --open` from this example's directory, and you should see the web application rendered in your browser.

![Rendered Vanilla example](example-vanilla.png)
3 changes: 3 additions & 0 deletions examples/vanilla/Trunk.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build]
target = "index.html"
dist = "dist"
Binary file added examples/vanilla/example-vanilla.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions examples/vanilla/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Trunk | Vanilla | web-sys</title>

<link data-trunk rel="scss" href="src/index.scss"/>
<link data-trunk rel="css" href="src/app.css"/>
<base data-trunk-public-url/>
</head>
<body>
<link data-trunk rel="rust" href="Cargo.toml" data-bin="vanilla-example"/>
</body>
</html>
1 change: 1 addition & 0 deletions examples/vanilla/src/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body {}
Loading

0 comments on commit 7126872

Please sign in to comment.