From 08c4238dcb6f3880e64b07e65220a4050694cf8f Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Tue, 11 Mar 2025 17:24:13 +0100 Subject: [PATCH] Replace 'wasm-pack' by 'trunk' --- .gitignore | 2 +- Cargo.lock | 24 ++++++++++++------------ README.md | 3 +-- backend/build.rs | 1 + backend/templates/base.html | 10 +++++----- deploy.nu | 5 +++-- frontend/Cargo.toml | 5 ----- frontend/Trunk.toml | 12 ++++++++++++ frontend/deploy.nu | 14 -------------- frontend/index.html | 7 +++++++ frontend/index.js | 8 -------- frontend/package.json | 12 ------------ frontend/rspack.config.js | 22 ---------------------- frontend/start.nu | 2 -- 14 files changed, 42 insertions(+), 85 deletions(-) create mode 100644 frontend/Trunk.toml delete mode 100644 frontend/deploy.nu create mode 100644 frontend/index.html delete mode 100644 frontend/index.js delete mode 100644 frontend/package.json delete mode 100644 frontend/rspack.config.js delete mode 100644 frontend/start.nu diff --git a/.gitignore b/.gitignore index adfeeca..d849085 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ target backend/data /deploy-to-pi.nu style.css.map -backend/static/frontend.js +backend/static/wasm/* backend/static/style.css backend/file.db backend/.sass-cache/* diff --git a/Cargo.lock b/Cargo.lock index f67041e..025d116 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -267,9 +267,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "base64ct" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +checksum = "bb97d56060ee67d285efb8001fec9d2a4c710c32efd2e14b5cbb5ba71930fc2d" [[package]] name = "basic-toml" @@ -377,9 +377,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.31" +version = "4.5.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "027bb0d98429ae334a8698531da7077bdf906419543a35a55c2cb1b66437d767" +checksum = "6088f3ae8c3608d19260cd7445411865a485688711b78b5be70d78cd96136f83" dependencies = [ "clap_builder", "clap_derive", @@ -387,9 +387,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.31" +version = "4.5.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5589e0cba072e0f3d23791efac0fd8627b49c829c196a492e88168e6a669d863" +checksum = "22a7ef7f676155edfb82daa97f99441f3ebf4a58d5e32f295a56259f1b6facc8" dependencies = [ "anstream", "anstyle", @@ -399,9 +399,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.28" +version = "4.5.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4ced95c6f4a675af3da73304b9ac4ed991640c36374e4b46795c49e17cf1ed" +checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7" dependencies = [ "heck", "proc-macro2", @@ -1394,9 +1394,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.7.1" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" +checksum = "3954d50fe15b02142bf25d3b8bdadb634ec3948f103d04ffe3031bc8fe9d7058" dependencies = [ "equivalent", "hashbrown 0.15.2", @@ -1473,9 +1473,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.170" +version = "0.2.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828" +checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" [[package]] name = "libm" diff --git a/README.md b/README.md index 0c90d8e..4c7fb44 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,7 @@ In directory '/backend' type: ### Tools needed nushell: https://www.nushell.sh/ -wasm-pack: https://github.com/rustwasm/wasm-pack -wasm-opt: $> cargo install wasm-opt +trunk: https://trunkrs.dev ### Compilation diff --git a/backend/build.rs b/backend/build.rs index 0af3eca..b30077f 100644 --- a/backend/build.rs +++ b/backend/build.rs @@ -28,6 +28,7 @@ fn main() { fn run_sass(command: &mut Command) -> Output { command + .arg("--no-source-map") .arg("scss/style.scss") .arg("static/style.css") .output() diff --git a/backend/templates/base.html b/backend/templates/base.html index c7cbb86..fdf4ef6 100644 --- a/backend/templates/base.html +++ b/backend/templates/base.html @@ -5,15 +5,15 @@ Recettes de cuisine +
diff --git a/deploy.nu b/deploy.nu index b1e9792..4fe6404 100644 --- a/deploy.nu +++ b/deploy.nu @@ -18,8 +18,9 @@ def main [host: string, destination: string, ssh_key: path] { } cd frontend - source frontend/deploy.nu - main true + # source frontend/deploy.nu + # main true + trunk build --release cd .. cargo test diff --git a/frontend/Cargo.toml b/frontend/Cargo.toml index 00bb315..533f5dc 100644 --- a/frontend/Cargo.toml +++ b/frontend/Cargo.toml @@ -56,8 +56,3 @@ gloo = "0.11" # all the `std::fmt` and `std::panicking` infrastructure, so isn't great for # code size when deploying. console_error_panic_hook = { version = "0.1", optional = true } - -# wasm-opt is used by default: https://docs.rs/wasm-opt/latest/wasm_opt/ -# Uncomment the following lines to disable it. -# [package.metadata.wasm-pack.profile.release] -# wasm-opt = false diff --git a/frontend/Trunk.toml b/frontend/Trunk.toml new file mode 100644 index 0000000..8e55a3e --- /dev/null +++ b/frontend/Trunk.toml @@ -0,0 +1,12 @@ +[build] +dist = "../backend/static/wasm" +public_url = "/static" +filehash = false +minify = "on_release" + +# Here we don't want the file 'index.html' in the final directory. +# Is there a way to not generate it at first? +[[hooks]] +stage = "post_build" +command = "rm" +command_arguments = ["../backend/static/wasm/.stage/index.html"] diff --git a/frontend/deploy.nu b/frontend/deploy.nu deleted file mode 100644 index 6b9d549..0000000 --- a/frontend/deploy.nu +++ /dev/null @@ -1,14 +0,0 @@ -def main [release: bool = false] { - - mut wasm_pack_args = [ build --target web --no-pack --no-typescript ] - if $release { - $wasm_pack_args ++= [ --release ] - } else { - $wasm_pack_args ++= [ --dev ] - } - - wasm-pack ...$wasm_pack_args - - cp pkg/frontend.js ../backend/static - cp pkg/frontend_bg.wasm ../backend/static -} \ No newline at end of file diff --git a/frontend/index.html b/frontend/index.html new file mode 100644 index 0000000..ce7f79b --- /dev/null +++ b/frontend/index.html @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/frontend/index.js b/frontend/index.js deleted file mode 100644 index ebc5567..0000000 --- a/frontend/index.js +++ /dev/null @@ -1,8 +0,0 @@ -// Note that a dynamic `import` statement here is required due to -// webpack/webpack#6615, but in theory `import { greet } from './pkg';` -// will work here one day as well! -const rust = import('./pkg'); - -rust - .then(m => m.greet('Paul!')) - .catch(console.error); \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json deleted file mode 100644 index 682de5c..0000000 --- a/frontend/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "scripts": { - "build": "rspack build", - "serve": "rspack serve" - }, - "devDependencies": { - "@rspack/cli": "^1.0.14", - "@rspack/core": "^1.0.14", - "@wasm-tool/wasm-pack-plugin": "1.5.0", - "html-webpack-plugin": "^5.6.0" - } -} \ No newline at end of file diff --git a/frontend/rspack.config.js b/frontend/rspack.config.js deleted file mode 100644 index 75e9eb7..0000000 --- a/frontend/rspack.config.js +++ /dev/null @@ -1,22 +0,0 @@ -const path = require('path'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); -const webpack = require('webpack'); -const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin"); - -module.exports = { - entry: './index.js', - output: { - path: path.resolve(__dirname, 'dist'), - filename: 'index.js', - }, - plugins: [ - new HtmlWebpackPlugin(), - new WasmPackPlugin({ - crateDirectory: path.resolve(__dirname, ".") - }), - ], - mode: 'development', - experiments: { - asyncWebAssembly: true - } -}; \ No newline at end of file diff --git a/frontend/start.nu b/frontend/start.nu deleted file mode 100644 index ede7328..0000000 --- a/frontend/start.nu +++ /dev/null @@ -1,2 +0,0 @@ -# See 'package.json'. -npm run serve \ No newline at end of file -- 2.49.0