86 lines
2.9 KiB
TypeScript
86 lines
2.9 KiB
TypeScript
// file: kb_app/vite.config.ts
|
|
|
|
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(() => ({
|
|
|
|
envPrefix: ['VITE_', 'TAURI_ENV_*'],
|
|
// 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/main.html')),
|
|
"splash": normalizePath(resolve(__dirname, 'frontend/splash.html')),
|
|
"demo_ws": normalizePath(resolve(__dirname, 'frontend/demo_ws.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: {
|
|
quietDeps: true,
|
|
silenceDeprecations: ["import", "color-functions", "global-builtin",],
|
|
verbose: false,
|
|
api: 'modern',
|
|
importers: [new NodePackageImporter()],
|
|
}
|
|
}
|
|
},
|
|
// 2. tauri expects a fixed port, fail if that port is not available
|
|
server: {
|
|
port: 1420,
|
|
strictPort: false,
|
|
host: host || false,
|
|
hmr: host
|
|
? {
|
|
protocol: "ws",
|
|
host,
|
|
port: 1421,
|
|
}
|
|
: undefined,
|
|
watch: {
|
|
ignored: ["**/src/**"],
|
|
},
|
|
},
|
|
}));
|