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/*
[[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"
[[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",
[[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",
[[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",
[[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",
[[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"
### 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
fn run_sass(command: &mut Command) -> Output {
command
+ .arg("--no-source-map")
.arg("scss/style.scss")
.arg("static/style.css")
.output()
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Recettes de cuisine</title>
<link rel="stylesheet" type="text/css" href="/static/style.css">
+ <link rel="modulepreload" href="/static/wasm/frontend.js" crossorigin="anonymous" as="fetch" type="application/wasm">
</head>
<body>
<script type="module">
- import init from '/static/frontend.js';
- async function run() {
- await init();
- }
- run();
+ import init, * as bindings from '/static/wasm/frontend.js';
+ const wasm = await init({ module_or_path: '/static/wasm/frontend_bg.wasm' });
+ window.wasmBindings = bindings;
+ dispatchEvent(new CustomEvent("TrunkApplicationStarted", {detail: {wasm}}));
</script>
<div id="toast"></div>
}
cd frontend
- source frontend/deploy.nu
- main true
+ # source frontend/deploy.nu
+ # main true
+ trunk build --release
cd ..
cargo test
# 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
--- /dev/null
+[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"]
+++ /dev/null
-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
--- /dev/null
+<html>
+ <head>
+ <link data-trunk rel="rust" data-wasm-opt="z" />
+ </head>
+ <body>
+ </body>
+</html>
\ No newline at end of file
+++ /dev/null
-// 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
+++ /dev/null
-{
- "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
+++ /dev/null
-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
+++ /dev/null
-# See 'package.json'.
-npm run serve
\ No newline at end of file