Skip to content

Commit bfbbefd

Browse files
authored
fix(cli): invalid plugin template (#8161)
1 parent fc571ea commit bfbbefd

File tree

14 files changed

+81
-62
lines changed

14 files changed

+81
-62
lines changed

.changes/fix-plugin-template.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@tauri-apps/cli": patch:bug
3+
"tauri-cli": patch:bug
4+
---
5+
6+
Fix invalid plugin template.

examples/api/vite.config.js

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,35 @@
55
import { defineConfig } from 'vite'
66
import Unocss from 'unocss/vite'
77
import { svelte } from '@sveltejs/vite-plugin-svelte'
8-
import { internalIpV4 } from 'internal-ip'
8+
import { internalIpV4Sync } from 'internal-ip'
9+
10+
const mobile = !!/android|ios/.exec(process.env.TAURI_ENV_PLATFORM)
911

1012
// https://vitejs.dev/config/
11-
export default defineConfig(async ({ command, mode }) => {
12-
const host =
13-
process.env.TAURI_ENV_PLATFORM === 'android' ||
14-
process.env.TAURI_ENV_PLATFORM === 'ios'
15-
? await internalIpV4()
16-
: 'localhost'
17-
return {
18-
plugins: [Unocss(), svelte()],
19-
build: {
20-
rollupOptions: {
21-
output: {
22-
entryFileNames: `assets/[name].js`,
23-
chunkFileNames: `assets/[name].js`,
24-
assetFileNames: `assets/[name].[ext]`
25-
}
26-
}
27-
},
28-
server: {
29-
host: '0.0.0.0',
30-
port: 5173,
31-
strictPort: true,
32-
hmr: {
33-
protocol: 'ws',
34-
host,
35-
port: 5183
36-
},
37-
fs: {
38-
allow: ['.', '../../tooling/api/dist']
13+
export default defineConfig({
14+
plugins: [Unocss(), svelte()],
15+
build: {
16+
rollupOptions: {
17+
output: {
18+
entryFileNames: `assets/[name].js`,
19+
chunkFileNames: `assets/[name].js`,
20+
assetFileNames: `assets/[name].[ext]`
3921
}
4022
}
23+
},
24+
server: {
25+
host: mobile ? '0.0.0.0' : false,
26+
port: 5173,
27+
strictPort: true,
28+
hmr: mobile
29+
? {
30+
protocol: 'ws',
31+
host: internalIpV4Sync(),
32+
port: 5183
33+
}
34+
: undefined,
35+
fs: {
36+
allow: ['.', '../../tooling/api/dist']
37+
}
4138
}
4239
})

tooling/cli/src/plugin/android.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub fn command(cli: Cli) -> Result<()> {
6868

6969
let mut data = BTreeMap::new();
7070
super::init::plugin_name_data(&mut data, &plugin_name);
71+
data.insert("android_package_id", handlebars::to_json(&plugin_id));
7172

7273
let mut created_dirs = Vec::new();
7374
template::render_with_generator(

tooling/cli/templates/plugin/__example-api/tauri-app/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
"tauri": "tauri"
1111
},
1212
"dependencies": {
13-
"@tauri-apps/api": "^1.1.0",
13+
"@tauri-apps/api": "^2.0.0-alpha.11",
1414
"tauri-plugin-{{ plugin_name }}-api": "link:../../"
1515
},
1616
"devDependencies": {
1717
"@sveltejs/vite-plugin-svelte": "^1.0.1",
18+
"internal-ip": "^7.0.0",
1819
"svelte": "^3.49.0",
1920
"vite": "^3.0.2",
20-
"@tauri-apps/cli": "^1.1.0"
21+
"@tauri-apps/cli": "^2.0.0-alpha.17"
2122
}
22-
}
23+
}

tooling/cli/templates/plugin/__example-api/tauri-app/src-tauri/Cargo.crate-manifest

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ repository = ""
88
edition = "2021"
99
rust-version = "1.70"
1010

11+
[lib]
12+
name = "tauri_app_lib"
13+
crate-type = ["staticlib", "cdylib", "rlib"]
14+
1115
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1216

1317
[build-dependencies]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
2+
#[tauri::command]
3+
fn greet(name: &str) -> String {
4+
format!("Hello, {}! You've been greeted from Rust!", name)
5+
}
6+
7+
#[cfg_attr(mobile, tauri::mobile_entry_point)]
8+
pub fn run() {
9+
tauri::Builder::default()
10+
.invoke_handler(tauri::generate_handler![greet])
11+
.plugin(tauri_plugin_{{ plugin_name_snake_case }}::init())
12+
.run(tauri::generate_context!())
13+
.expect("error while running tauri application");
14+
}
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
22
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
33

4-
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
5-
#[tauri::command]
6-
fn greet(name: &str) -> String {
7-
format!("Hello, {}! You've been greeted from Rust!", name)
8-
}
9-
104
fn main() {
11-
tauri::Builder::default()
12-
.invoke_handler(tauri::generate_handler![greet])
13-
.plugin(tauri_plugin_{{ plugin_name_snake_case }}::init())
14-
.run(tauri::generate_context!())
15-
.expect("error while running tauri application");
5+
tauri_app_lib::run();
166
}
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { defineConfig } from "vite";
22
import { svelte } from "@sveltejs/vite-plugin-svelte";
3+
import { internalIpV4Sync } from 'internal-ip'
4+
5+
const mobile = !!/android|ios/.exec(process.env.TAURI_ENV_PLATFORM);
36

47
// https://vitejs.dev/config/
58
export default defineConfig({
@@ -10,18 +13,13 @@ export default defineConfig({
1013
clearScreen: false,
1114
// tauri expects a fixed port, fail if that port is not available
1215
server: {
16+
host: mobile ? "0.0.0.0" : false,
1317
port: 1420,
1418
strictPort: true,
19+
hmr: mobile ? {
20+
protocol: 'ws',
21+
host: internalIpV4Sync(),
22+
port: 1421
23+
} : undefined,
1524
},
16-
// to make use of `TAURI_ENV_DEBUG` and other env variables
17-
// https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
18-
envPrefix: ["VITE_", "TAURI_ENV_"],
19-
build: {
20-
// Tauri supports es2021
21-
target: ["es2021", "chrome100", "safari13"],
22-
// don't minify for debug builds
23-
minify: !process.env.TAURI_ENV_DEBUG ? "esbuild" : false,
24-
// produce sourcemaps for debug builds
25-
sourcemap: !!process.env.TAURI_ENV_DEBUG,
26-
},
27-
});
25+
})

tooling/cli/templates/plugin/__example-basic/vanilla/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"author": "",
1010
"license": "MIT",
1111
"dependencies": {
12-
"@tauri-apps/cli": "^1.0.0"
12+
"@tauri-apps/cli": "^2.0.0-alpha.17"
1313
}
1414
}

tooling/cli/templates/plugin/__example-basic/vanilla/src-tauri/Cargo.crate-manifest

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ repository = ""
88
edition = "2021"
99
rust-version = "1.70"
1010

11+
[lib]
12+
name = "tauri_app_lib"
13+
crate-type = ["staticlib", "cdylib", "rlib"]
14+
1115
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1216

1317
[build-dependencies]

0 commit comments

Comments
 (0)