Tauri from cra
Create a react application using cra(create-react-app) and then include a tauri(Change cra to tauri app).
Prepare
- Install webview2(on windows), rust and node
- Install package manager cargo and yarn
Create react app
Create a normal cra with ts template.
1 | yarn create react-app <app name> --template typescript |
Add tauri dependencies
yarn install @tauri-apps/cli
yarn install -D @tauri-apps/api
Init tauri project
You can select all options as default.
1 | yarn tauri init |
Set tauri config
Startup react before running tauri, and build react before build tauri application.
- Open
src-tauri/src/tauri.conf.json
- Set
build.beforeDevCommand
toyarn start
or other command to start react dev server. - Set
build.beforeBuildCommand
toyarn.build
or other command to build react to distdir.
Start tauri in node
Set scripts to start tauri in react app.
Open package.json and add scripts.
1
yarn tauri dev
Rust will build your package which defined in
Cargo.toml
.It will download dependencies using cargo first time, take a rest. Set another cargo registry may quickly.
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 AlMirai!