Replace 'wasm-pack' by 'trunk'
This commit is contained in:
parent
ec582ad68f
commit
08c4238dcb
14 changed files with 42 additions and 85 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -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/*
|
||||
|
|
|
|||
24
Cargo.lock
generated
24
Cargo.lock
generated
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -5,15 +5,15 @@
|
|||
<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>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
12
frontend/Trunk.toml
Normal file
12
frontend/Trunk.toml
Normal file
|
|
@ -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"]
|
||||
|
|
@ -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
|
||||
}
|
||||
7
frontend/index.html
Normal file
7
frontend/index.html
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<link data-trunk rel="rust" data-wasm-opt="z" />
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -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);
|
||||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
};
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
# See 'package.json'.
|
||||
npm run serve
|
||||
Loading…
Add table
Add a link
Reference in a new issue