Files
tauri-video03/vite.config.ts
2026-03-30 23:38:47 +02:00

78 lines
2.6 KiB
TypeScript

import { defineConfig, normalizePath } from "vite";
import { NodePackageImporter } from "sass-embedded";
import { resolve } from 'path';
const host = process.env.TAURI_DEV_HOST;
// https://vite.dev/config/
export default defineConfig(async () => ({
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
//
// 1. prevent Vite from obscuring rust errors
clearScreen: false,
root: 'frontend', // Set this to your frontend directory
publicDir: 'public',
build: {
outDir: './dist', // Output directory for the build
emptyOutDir: true,
rollupOptions: {
input: {
"main": normalizePath(resolve(__dirname, 'frontend/index.html'))
},
output: {
entryFileNames: 'js/[name]-[hash].js',
chunkFileNames: 'js/chunks/[name]-[hash].js',
assetFileNames: (assetInfo) => {
const originalName = assetInfo.name ?? '';
const ext = originalName.substring(originalName.lastIndexOf('.') + 1).toLowerCase();
if (ext === 'js') {
return 'js/[name]-[hash][extname]';
}
// CSS
if (ext === 'css') {
return 'css/[name]-[hash][extname]';
}
if (['eot', 'otf', 'ttf', 'woff', 'woff2'].includes(ext)) {
return 'fonts/[name]-[hash][extname]';
}
if (['png', 'jpg', 'jpeg', 'gif', 'svg', 'webp', 'ico'].includes(ext)) {
return 'imgs/[name][extname]';
}
if (['mp4', 'webm'].includes(ext)) {
return 'videos/[name][extname]';
}
return 'otherassets/[name][extname]';
},
},
},
minify: true,
sourcemap: false,
cssCodeSplit: true
},
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
importers: [new NodePackageImporter()],
}
}
},
// 2. tauri expects a fixed port, fail if that port is not available
server: {
port: 1420,
strictPort: true,
host: host || false,
hmr: host
? {
protocol: "ws",
host,
port: 1421,
}
: undefined,
watch: {
ignored: ["**/src/**"],
},
},
}));