diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ad288173..8db459e5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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: @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 52af3192..7d23bc1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 `` 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. diff --git a/examples/seed/Cargo.lock b/examples/seed/Cargo.lock index 11e6c548..d7d5fc99 100644 --- a/examples/seed/Cargo.lock +++ b/examples/seed/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "autocfg" version = "1.0.1" @@ -353,9 +355,9 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" -version = "1.0.24" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" dependencies = [ "unicode-xid", ] @@ -482,6 +484,7 @@ dependencies = [ "seed", "serde", "uuid", + "wasm-bindgen", ] [[package]] @@ -602,9 +605,9 @@ checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" [[package]] name = "syn" -version = "1.0.60" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" +checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" dependencies = [ "proc-macro2", "quote", @@ -706,9 +709,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.70" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be" +checksum = "83240549659d187488f91f33c0f8547cbfef0b2088bc470c116d1d260ef623d9" dependencies = [ "cfg-if 1.0.0", "serde", @@ -718,9 +721,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.70" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bc45447f0d4573f3d65720f636bbcc3dd6ce920ed704670118650bcd47764c7" +checksum = "ae70622411ca953215ca6d06d3ebeb1e915f0f6613e3b495122878d7ebec7dae" dependencies = [ "bumpalo", "lazy_static", @@ -745,9 +748,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.70" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b8853882eef39593ad4174dd26fc9865a64e84026d223f63bb2c42affcbba2c" +checksum = "3e734d91443f177bfdb41969de821e15c516931c3c3db3d318fa1b68975d0f6f" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -755,9 +758,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.70" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4133b5e7f2a531fa413b3a1695e925038a05a71cf67e87dafa295cb645a01385" +checksum = "d53739ff08c8a68b0fdbcd54c372b8ab800b1449ab3c9d706503bc7dd1621b2c" dependencies = [ "proc-macro2", "quote", @@ -768,9 +771,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.70" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd4945e4943ae02d15c13962b38a5b1e81eadd4b71214eee75af64a4d6a4fd64" +checksum = "d9a543ae66aa233d14bb765ed9af4a33e81b8b58d1584cf1b47ff8cd0b9e4489" [[package]] name = "web-sys" diff --git a/examples/seed/Cargo.toml b/examples/seed/Cargo.toml index c2416589..ab801705 100644 --- a/examples/seed/Cargo.toml +++ b/examples/seed/Cargo.toml @@ -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. diff --git a/examples/vanilla/Cargo.lock b/examples/vanilla/Cargo.lock new file mode 100644 index 00000000..9a8d665b --- /dev/null +++ b/examples/vanilla/Cargo.lock @@ -0,0 +1,210 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "bumpalo" +version = "3.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099e596ef14349721d9016f6b80dd3419ea1bf289ab9b44df8e4dfd3a005d5d9" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "console_error_panic_hook" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211" +dependencies = [ + "cfg-if 0.1.10", + "wasm-bindgen", +] + +[[package]] +name = "js-sys" +version = "0.3.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d99f9e3e84b8f67f846ef5b4cbbc3b1c29f6c759fcbce6f01aa0e73d932a24c" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "memory_units" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" + +[[package]] +name = "proc-macro2" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "1.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "vanilla-example" +version = "0.1.0" +dependencies = [ + "console_error_panic_hook", + "wasm-bindgen", + "web-sys", + "wee_alloc", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83240549659d187488f91f33c0f8547cbfef0b2088bc470c116d1d260ef623d9" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae70622411ca953215ca6d06d3ebeb1e915f0f6613e3b495122878d7ebec7dae" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e734d91443f177bfdb41969de821e15c516931c3c3db3d318fa1b68975d0f6f" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53739ff08c8a68b0fdbcd54c372b8ab800b1449ab3c9d706503bc7dd1621b2c" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9a543ae66aa233d14bb765ed9af4a33e81b8b58d1584cf1b47ff8cd0b9e4489" + +[[package]] +name = "web-sys" +version = "0.3.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a905d57e488fec8861446d3393670fb50d27a262344013181c2cdf9fff5481be" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wee_alloc" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "memory_units", + "winapi", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/examples/vanilla/Cargo.toml b/examples/vanilla/Cargo.toml new file mode 100644 index 00000000..6b79bf1a --- /dev/null +++ b/examples/vanilla/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "vanilla-example" +version = "0.1.0" +authors = ["Philip Peterson "] +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" diff --git a/examples/vanilla/README.md b/examples/vanilla/README.md new file mode 100644 index 00000000..c8968be4 --- /dev/null +++ b/examples/vanilla/README.md @@ -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) diff --git a/examples/vanilla/Trunk.toml b/examples/vanilla/Trunk.toml new file mode 100644 index 00000000..842cc2f7 --- /dev/null +++ b/examples/vanilla/Trunk.toml @@ -0,0 +1,3 @@ +[build] +target = "index.html" +dist = "dist" diff --git a/examples/vanilla/example-vanilla.png b/examples/vanilla/example-vanilla.png new file mode 100644 index 00000000..1aef6873 Binary files /dev/null and b/examples/vanilla/example-vanilla.png differ diff --git a/examples/vanilla/index.html b/examples/vanilla/index.html new file mode 100644 index 00000000..65001600 --- /dev/null +++ b/examples/vanilla/index.html @@ -0,0 +1,15 @@ + + + + + + Trunk | Vanilla | web-sys + + + + + + + + + diff --git a/examples/vanilla/src/app.css b/examples/vanilla/src/app.css new file mode 100644 index 00000000..208d16d4 --- /dev/null +++ b/examples/vanilla/src/app.css @@ -0,0 +1 @@ +body {} diff --git a/examples/vanilla/src/index.scss b/examples/vanilla/src/index.scss new file mode 100644 index 00000000..820afe56 --- /dev/null +++ b/examples/vanilla/src/index.scss @@ -0,0 +1,9 @@ +@charset "utf-8"; + +html { + body { + font-size: 20pt; + color: #111; + font-family: sans-serif; + } +} diff --git a/examples/vanilla/src/main.rs b/examples/vanilla/src/main.rs new file mode 100644 index 00000000..04b3e833 --- /dev/null +++ b/examples/vanilla/src/main.rs @@ -0,0 +1,26 @@ +#![recursion_limit = "1024"] + +#[global_allocator] +static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; + +use console_error_panic_hook::set_once as set_panic_hook; +use wasm_bindgen::prelude::*; +use web_sys::window; + +fn start_app() { + let document = window().and_then(|win| win.document()).expect("Could not access document"); + let body = document.body().expect("Could not access document.body"); + let text_node = document.create_text_node("Hello, world from Vanilla Rust!"); + body.append_child(text_node.as_ref()).expect("Failed to append text"); +} + +#[wasm_bindgen(inline_js = "export function snippetTest() { console.log('Hello from JS FFI!'); }")] +extern "C" { + fn snippetTest(); +} + +fn main() { + set_panic_hook(); + snippetTest(); + start_app(); +} diff --git a/examples/yew/Cargo.toml b/examples/yew/Cargo.toml index 7c713270..62026cc1 100644 --- a/examples/yew/Cargo.toml +++ b/examples/yew/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] console_error_panic_hook = "0.1.6" -wasm-bindgen = "=0.2.70" # This is pinned primarily for CI stability. +wasm-bindgen = "=0.2.73" # This is pinned primarily for CI stability. wee_alloc = "0.4.5" ybc = "0.1.4" yew = "0.17.3" diff --git a/examples/yew/index.html b/examples/yew/index.html index b7fda7b0..5e552d1e 100644 --- a/examples/yew/index.html +++ b/examples/yew/index.html @@ -11,7 +11,6 @@ - diff --git a/examples/yew/src/inline-css.css b/examples/yew/src/inline-css.css deleted file mode 100644 index 7a7c4fe9..00000000 --- a/examples/yew/src/inline-css.css +++ /dev/null @@ -1,4 +0,0 @@ -/* This is purely for demo purposes and does nothing whatsoever `:)` */ -html { - background-color: inherit; -} diff --git a/src/pipelines/mod.rs b/src/pipelines/mod.rs index 7317cf08..77022f2b 100644 --- a/src/pipelines/mod.rs +++ b/src/pipelines/mod.rs @@ -168,10 +168,7 @@ impl AssetFile { Some(file_stem) => file_stem.to_owned(), None => bail!("asset has no file name stem {:?}", &path), }; - let ext = match path.extension() { - Some(ext) => Some(ext.to_owned().to_string_lossy().to_string()), - None => None, - }; + let ext = path.extension().map(|ext| ext.to_owned().to_string_lossy().to_string()); Ok(Self { path: path.into(), file_name,