You need to enable JavaScript to run this app. Tauri生产构建后无法访问新增index2.html,调试正常且配置修改无效
优惠活动
大模型
产品
解决方案
定价
更多

Tauri生产构建后无法访问新增index2.html,调试正常且配置修改无效

解决Tauri生产构建后无法访问index2.html的问题

问题根源

你的vite.config.ts配置存在嵌套错误:你把rollupOptions放在了build字段内部的另一个build子字段里,这会导致Vite无法正确识别多页面入口配置。

修正后的Vite配置

将嵌套的build字段移除,把rollupOptions直接放在顶层build对象下:

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

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

export default defineConfig(async () => ({
  clearScreen: false,
  server: {
    port: 1420,
    strictPort: true,
  },
  envPrefix: ["VITE_", "TAURI_"],
  build: {
    target: process.env.TAURI_PLATFORM == "windows" ? "chrome105" : "safari13",
    minify: !process.env.TAURI_DEBUG ? "esbuild" : false,
    sourcemap: !!process.env.TAURI_DEBUG,
    // 修正:rollupOptions直接放在build下,而非嵌套的build中
    rollupOptions: {
      input: {
        index: resolve(__dirname, 'index.html'),
        index2: resolve(__dirname, 'index2.html'),
      },
    },
  },
}));

额外验证与优化步骤

  1. 执行cargo tauri build后,检查项目根目录下的dist文件夹,确认index2.html是否已生成
  2. 如果需要在新窗口打开页面,建议使用Tauri的窗口API替代普通a标签:
    import { Window } from '@tauri-apps/api/window';
    // 在点击事件中触发
    new Window('second-window', {
      url: 'index2.html'
    });
    

内容的提问来源于stack exchange,提问作者Popeye

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 17:32:35