Skip to content

A local-first personal finance app

1.3 KB
Raw Blame
import path from 'path';

import { peggyLoader } from '@actual-app/vite-plugin-peggy';
import { visualizer } from 'rollup-plugin-visualizer';
import { defineConfig } from 'vite';

export default defineConfig(({ mode }) => {
  const outDir = path.resolve(__dirname, 'lib-dist/electron');

  return {
    mode,
    ssr: {
      noExternal: true,
      external: ['better-sqlite3'],
      resolve: { conditions: ['electron'] },
    },
    build: {
      target: 'node18',
      outDir,
      emptyOutDir: true,
      ssr: true,
      lib: {
        entry: path.resolve(__dirname, 'src/server/main.ts'),
        formats: ['cjs'],
      },
      sourcemap: true,
      rolldownOptions: {
        output: {
          entryFileNames: 'bundle.desktop.js',
          format: 'cjs',
          name: 'desktop',
        },
      },
    },
    resolve: {
      conditions: ['electron'],
      // oxlint-disable-next-line actual/enforce-boundaries -- handlebars types only resolve from the root entry; the alias forces the pre-compiled dist bundle at build time
      alias: [
        {
          find: 'handlebars',
          replacement: require.resolve('handlebars/dist/handlebars.js'),
        },
      ],
    },
    plugins: [
      peggyLoader(),
      visualizer({ template: 'raw-data', filename: `${outDir}/stats.json` }),
    ],
  };
});