Loading script from public folder not working #863
-
Hi folks. The setupI used this template to get started: use leptos::logging::log;
use leptos::*;
use leptos_meta::*;
use leptos_router::*;
fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(|| {
view! {
<App />
}
})
}
#[component]
pub fn App() -> impl IntoView {
provide_meta_context();
view! {
<Html lang="en" dir="ltr" attr:data-theme="light"/>
<Title text="Welcome to Leptos CSR"/>
<Meta charset="UTF-8"/>
<Meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<Router>
<Routes>
<Route path="/" view=Page/>
</Routes>
</Router>
}
}
#[component]
pub fn Page() -> impl IntoView {
view! {
<script data-trunk src="qr-scanner.umd.min.js" rel="copy-file"></script>
}
} My files look like this: .
├── Cargo.lock
├── Cargo.toml
├── README.md
├── Trunk.toml
├── dist
│ ├── csr-b8cf5b1ae7a29d15.js
│ ├── csr-b8cf5b1ae7a29d15_bg.wasm
│ ├── favicon-e9cbd8f50cc65bf2.ico
│ ├── index.html
│ └── styles-b3c1c68ee90b19f9.css
├── index.html
├── public
│ ├── favicon.ico
│ ├── qr-scanner-worker.min.js
│ ├── qr-scanner.umd.min.js
│ └── styles.css
├── rust-toolchain.toml
└── src
└── main.rs My [[hooks]]
stage = "build"
command = "cp"
command_arguments = ["-r", "public", "dist"] My [package]
name = "csr"
version = "0.1.0"
edition = "2021"
authors = ["Dominik Wilkowski <Hi@Dominik-Wilkowski.com>"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
leptos = { version = "0.6", features = ["csr", "nightly"] }
leptos_meta = { version = "0.6", features = ["csr", "nightly"] }
leptos_router = { version = "0.6", features = ["csr", "nightly"] }
console_log = "1"
log = "0.4"
console_error_panic_hook = "0.1"
leptos-qr-scanner = { path = "../.." }
# utils
# strum = { version = "0.25", features = ["derive", "strum_macros"] }
# strum_macros = "0.25"
[dev-dependencies]
wasm-bindgen = "0.2"
wasm-bindgen-test = "0.3"
web-sys = { version = "0.3", features = ["Document", "Window"] }
[profile.release]
opt-level = 'z'
lto = true
codegen-units = 1
panic = "abort" I'm using The issueThe script I'm trying to include just wont copy into the dist folder. I tried: <script src="qr-scanner.umd.min.js" data-no-minify data-trunk rel="inline"></script>
<script src="/qr-scanner.umd.min.js" data-no-minify data-trunk rel="inline"></script>
<script src="public/qr-scanner.umd.min.js" data-no-minify data-trunk rel="inline"></script>
<script src="/public/qr-scanner.umd.min.js" data-no-minify data-trunk rel="inline"></script> I also tried: <script src="qr-scanner.umd.min.js" data-trunk rel="inline"></script>
<script src="/qr-scanner.umd.min.js" data-trunk rel="inline"></script>
<script src="public/qr-scanner.umd.min.js" data-trunk rel="inline"></script>
<script src="/public/qr-scanner.umd.min.js" data-trunk rel="inline"></script> and <script src="qr-scanner.umd.min.js" data-trunk rel="copy-file"></script>
<script src="/qr-scanner.umd.min.js" data-trunk rel="copy-file"></script>
<script src="public/qr-scanner.umd.min.js" data-trunk rel="copy-file"></script>
<script src="/public/qr-scanner.umd.min.js" data-trunk rel="copy-file"></script> and <script src="qr-scanner.umd.min.js" data-trunk rel="copy-dir"></script>
<script src="/qr-scanner.umd.min.js" data-trunk rel="copy-dir"></script>
<script src="public/qr-scanner.umd.min.js" data-trunk rel="copy-dir"></script>
<script src="/public/qr-scanner.umd.min.js" data-trunk rel="copy-dir"></script> even: <script src="qr-scanner.umd.min.js" data-trunk data-target-path="/" rel="copy-file"></script>
<script src="/qr-scanner.umd.min.js" data-trunk data-target-path="/" rel="copy-file"></script>
<script src="public/qr-scanner.umd.min.js" data-trunk data-target-path="/" rel="copy-file"></script>
<script src="/public/qr-scanner.umd.min.js" data-trunk data-target-path="/" rel="copy-file"></script>
<script src="qr-scanner.umd.min.js" data-trunk data-target-path="qr-scanner.umd.min.js" rel="copy-file"></script>
<script src="/qr-scanner.umd.min.js" data-trunk data-target-path="/qr-scanner.umd.min.js" rel="copy-file"></script>
<script src="public/qr-scanner.umd.min.js" data-trunk data-target-path="public/qr-scanner.umd.min.js" rel="copy-file"></script>
<script src="/public/qr-scanner.umd.min.js" data-trunk data-target-path="/public/qr-scanner.umd.min.js" rel="copy-file"></script>
<script src="qr-scanner.umd.min.js" type="text/javascript"></script> I would be happy for it to inline... anything at this point really. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
I am trying to reproduce this (with 0.21.0.rc-3) and report what I find:
I was also able to create a file <!DOCTYPE html>
<html>
<head>
<script src="/public/test.js" data-no-minify data-trunk rel="inline"></script> <!-- HERE -->
</head>
<body></body>
</html> And running
Maybe you can add |
Beta Was this translation helpful? Give feedback.
You need to add the script to the index.html, otherwise it won't be processed by trunk.
Alternatively, you can aim for an approach with
wasm-bindgen
, binding the JS API to Rust. That will lead to wasm-bindgen doing the processing, and trunk picking that up.