61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import react from '@vitejs/plugin-react-swc';
|
|
import { componentTagger } from 'lovable-tagger';
|
|
import { defineConfig } from 'vite';
|
|
|
|
// https://vitejs.dev/config/
|
|
const rootDir = fileURLToPath(new URL('.', import.meta.url));
|
|
const srcDir = path.resolve(rootDir, 'src');
|
|
|
|
const noteflowAlias = () => ({
|
|
name: 'noteflow-alias',
|
|
enforce: 'pre' as const,
|
|
async resolveId(this: unknown, source: string, importer: string | undefined) {
|
|
if (!source.startsWith('@/')) {
|
|
return null;
|
|
}
|
|
const target = path.resolve(srcDir, source.slice(2));
|
|
const resolved = await (this as { resolve: (...args: unknown[]) => Promise<unknown> }).resolve(target, importer, { skipSelf: true });
|
|
if (!resolved) {
|
|
return target;
|
|
}
|
|
if (typeof resolved === 'string') {
|
|
return resolved;
|
|
}
|
|
return (resolved as { id: string }).id;
|
|
},
|
|
});
|
|
|
|
export default defineConfig(({ mode }) => ({
|
|
server: {
|
|
host: '::',
|
|
port: 5173,
|
|
watch: {
|
|
usePolling: true,
|
|
},
|
|
hmr: {
|
|
host: process.env.VITE_HMR_HOST,
|
|
},
|
|
},
|
|
plugins: [noteflowAlias(), react(), mode === 'development' && componentTagger()].filter(Boolean),
|
|
resolve: {
|
|
alias: [
|
|
{ find: /^@\//, replacement: `${srcDir}/` },
|
|
// Mock Tauri plugins for web-only builds (actual plugins only available in Tauri runtime)
|
|
{
|
|
find: '@tauri-apps/plugin-shell',
|
|
replacement: path.resolve(rootDir, 'src/test/mocks/tauri-plugin-shell.ts'),
|
|
},
|
|
{
|
|
find: '@tauri-apps/plugin-deep-link',
|
|
replacement: path.resolve(rootDir, 'src/test/mocks/tauri-plugin-deep-link.ts'),
|
|
},
|
|
],
|
|
},
|
|
optimizeDeps: {
|
|
// Exclude Tauri plugins from pre-bundling (only available in Tauri runtime)
|
|
exclude: ['@tauri-apps/plugin-shell', '@tauri-apps/plugin-deep-link'],
|
|
},
|
|
}));
|