Search code examples
rustbuildvitetauri

Tauri Production Build


I am working with Rust and tauri. I have created the base application. If I build it works fine after installation

# build command
cargo tauri build

# installation
sudo dpkg -i tauri-app.0.0.0.deb

For next step I have created a new file index2.html and in index.html I have added the following lines

<a href="index2.html">Open the second file </a>

if i run with following command:

cargo tauri dev

works fine, I can access index2.html but if I build and install, index2 cannot be found.

Any help will be appreciated.

----- EDIT ------

After reading Creating additional HTML pages I made some improvement. I have added this following code in vite.config.ts

import { defineConfig } from "vite";
import { resolve } from 'path';

const mobile =
  process.env.TAURI_PLATFORM === "android" ||
  process.env.TAURI_PLATFORM === "ios";

// https://vitejs.dev/config/
export default defineConfig(async () => ({
  // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
  // prevent vite from obscuring rust errors
  clearScreen: false,
  // tauri expects a fixed port, fail if that port is not available
  server: {
    port: 1420,
    strictPort: true,
  },
  // to make use of `TAURI_DEBUG` and other env variables
  // https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
  envPrefix: ["VITE_", "TAURI_"],
  build: {
    // Tauri supports es2021
    target: process.env.TAURI_PLATFORM == "windows" ? "chrome105" : "safari13",
    // don't minify for debug builds
    minify: !process.env.TAURI_DEBUG ? "esbuild" : false,
    // produce sourcemaps for debug builds
    sourcemap: !!process.env.TAURI_DEBUG,
// added code
    build: {
      rollupOptions: {
        input: {
          index: resolve(__dirname, 'index.html'),
          index2: resolve(__dirname, 'index2.html'),
        },
      },
    },
  },
}));

But, not seeing any improvement.


Solution

  • I have solved the issue.

    1. Latest create-tauri-app command inject all vite by default.
    2. I needed to tell vite to process my html files other than index.html to do so, I had to register filenames in vite.config.ts file. details are described in the following page Creating additional HTML pages
    3. I had some issue with images. To resolve this I followed guide from this vite page Importing Asset as URL