Rust + WebAssembly를 사용하여 Frontend Browser 앱을 구축하십시오. 서버 측 렌더링을 지원합니다.
이 readme는 Percy에 대한 가벼운 소개를 제공합니다. Percy Book을 확인하십시오.
퍼시는 하나의 경고로 안정적인 녹에 컴파일합니다.
야간 녹에서는 따옴표없이 텍스트 노드를 만들 수 있습니다.
// Nightly Rust does not require quotes around text nodes.
html ! { <div> My text nodes here </div> } ;안정된 녹에는 견적 마크가 필요합니다.
// Stable Rust requires quotes around text nodes.
html ! { <div> { "My text nodes here " } </div> } ;이 차이는 Rust Compiler -Rust 추적 문제에서 스팬 위치가 안정화되면 사라집니다.
속도를 높이는 가장 좋은 방법은 Percy Book을 확인하는 것이지만 발을 적시는 매우 기본적인 예입니다.
Percy를 사용하면 서버 측 렌더링 만있는 응용 프로그램을 만들 수 있습니다.
다음은 현재 시도 할 수있는 클라이언트 측 렌더링의 빠르고 진실한 예제입니다.
먼저 사용하여 새 프로젝트를 만듭니다
cargo new client-side-web-app --lib
cd client-side-web-app프로젝트에 다음 파일을 추가하십시오.
touch build.sh
touch index.html
touch app.css디렉토리 구조는 다음과 같습니다.
.
├── Cargo.toml
├── build.sh
├── index.html
├── app.css
└── src
└── lib.rs이제 다음 내용으로 각 파일을 편집하십시오.
# contents of build.sh
#! /bin/bash
cd " $( dirname " $0 " ) "
mkdir -p public
cargo build --target wasm32-unknown-unknown
wasm-bindgen target/wasm32-unknown-unknown/debug/client_side_web_app.wasm --no-typescript --target web --out-dir ./public --debug
cp index.html public/
cp app.css public/ // contents of src/lib.rs
use wasm_bindgen :: prelude :: * ;
use web_sys ;
use percy_dom :: prelude :: * ;
# [ wasm_bindgen ]
struct App {
pdom : PercyDom
}
# [ wasm_bindgen ]
impl App {
# [ wasm_bindgen ( constructor ) ]
pub fn new ( ) -> App {
let start_view = html ! { <div> Hello </div> } ;
let window = web_sys :: window ( ) . unwrap ( ) ;
let document = window . document ( ) . unwrap ( ) ;
let body = document . body ( ) . unwrap ( ) ;
let mut pdom = PercyDom :: new_append_to_mount ( start_view , & body ) ;
let greetings = "Hello, World!" ;
let end_view = html ! {
// Use regular Rust comments within your html
<div class= [ "big" , "blue" ] >
/* Interpolate values using braces */
<strong> { greetings } </strong>
<button
class= "giant-button"
onclick=|_event| {
web_sys :: console :: log_1 ( & "Button Clicked!" . into ( ) ) ;
}
>
// No need to wrap text in quotation marks (:
Click me and check your console
</button>
</div>
} ;
pdom . update ( end_view ) ;
App { pdom }
}
} # contents of Cargo.toml
[ package ]
name = " client-side-web-app "
version = " 0.1.0 "
authors = [ " Friends of Percy " ]
edition = " 2018 "
[ lib ]
crate-type = [ " cdylib " ] # Don't forget this!
[ dependencies ]
wasm-bindgen = " 0.2 "
js-sys = " 0.3 "
percy-dom = " 0.9 "
[ dependencies . web-sys ]
version = " 0.3 "
features = [
" Document " ,
" MouseEvent " ,
" Window " ,
" console "
] <!-- contents of index.html -->
<!DOCTYPE html >
< html lang =" en " >
< head >
< meta charset =" UTF-8 " >
< meta name =" viewport " content =" width=device-width, initial-scale=1 " >
< link rel =" stylesheet " type =" text/css " href =" app.css " />
< title > Client Side Demo </ title >
</ head >
< body style =' margin: 0; padding: 0; width: 100%; height: 100%; ' >
< script type =" module " >
import init , { App } from '/client_side_web_app.js'
async function run ( ) {
await init ( '/client_side_web_app_bg.wasm' )
new App ( )
}
run ( )
</ script >
</ body >
</ html > /* contents of app.css */
. big {
font-size : 30 px ;
}
. blue {
color : blue;
}
. giant-button {
font-size : 24 px ;
font-weight : bold;
}이제 실행됩니다
# Used to compile your Rust code to WebAssembly
cargo install wasm-bindgen-cli
# Or any other static file server that supports the application/wasm mime type
cargo install https
chmod +x ./build.sh
./build.sh
# Visit localhost:8080 in your browser
http ./public --port 8080다음을 볼 수 있습니다.

잘 했어!
동형 웹 앱
단위 테스트 뷰 구성 요소
유용한 예제에 대한 아이디어가 있으면 문제 또는 PR을 열십시오!
Percy-Dom API 문서
HTML-MACRO API 문서
Percy-Router API 문서
질문 / 생각이 있으면 항상 문제와 PR을 열어 줄 수 있습니다!
기본적이거나 간단하다고 느더라도 - 당신이 자신을 빨리 대답 할 수 없다는 질문이 있다면 그것은 문서의 실패입니다.
Codebase에 기여하는 방법에 대한 자세한 정보는 Percy Book의 기여 섹션에서 찾을 수 있습니다!
모든 장치, 통합 및 브라우저 테스트를 실행하려면 종속성을 잡은 다음 :
./test.shMIT