代码拉取完成,页面将自动刷新
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { copyFileSync, mkdirSync, existsSync, readdirSync } from "fs";
import { join } from "path";
const host = process.env.TAURI_DEV_HOST;
// https://vitejs.dev/config/
// 自定义插件:复制i18n locales到src-tauri
const copyI18nPlugin = () => {
return {
name: 'copy-i18n-locales',
buildStart() {
const srcLocalesDir = join(process.cwd(), 'src-ui', 'i18n', 'locales');
const destDir = join(process.cwd(), 'src-tauri', 'locales');
// 创建目标目录
if (!existsSync(destDir)) {
mkdirSync(destDir, { recursive: true });
}
if (!existsSync(destDir)) {
mkdirSync(destDir, { recursive: true });
}
// 复制locales文件夹中的所有文件
try {
const files = readdirSync(srcLocalesDir);
files.forEach(file => {
const srcFile = join(srcLocalesDir, file);
const destFile = join(destDir, file);
copyFileSync(srcFile, destFile);
});
console.log(`✓ ${files.length} i18n locales files copied to src-tauri/locales/`);
} catch (error) {
console.error('Failed to copy i18n locales:', error);
}
}
};
};
export default defineConfig(async () => ({
plugins: [vue(), copyI18nPlugin()],
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
//
// 1. prevent vite from obscuring rust errors
clearScreen: false,
// 2. tauri expects a fixed port, fail if that port is not available
server: {
port: 12345,
strictPort: true,
host: host || false,
hmr: host
? {
protocol: "ws",
host,
port: 1421,
}
: undefined,
watch: {
// 3. tell vite to ignore watching `src-tauri`
ignored: ["**/src-tauri/**"],
},
},
}));
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。