aboutsummaryrefslogtreecommitdiffstats
path: root/packages/renderer/vite.config.js
blob: e20e0f1dab9d97322b5e009c56ff049667fdc8a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* eslint-disable no-process-env */
/* eslint-env node */

import { builtinModules } from 'module';
import { join } from 'path';

import react from '@vitejs/plugin-react';

import { banner, chrome } from '../../config/buildConstants.js';
import fileURLToDirname from '../../config/fileURLToDirname.js';

const thisDir = fileURLToDirname(import.meta.url);

const mode = process.env.MODE || 'development';

const isDevelopment = mode === 'development';

/**
 * @type {import('vite').UserConfig}
 * @see https://vitejs.dev/config/
 */
export default {
  /** @type {import('vite').LogLevel} */
  logLevel: 'info',
  mode,
  root: thisDir,
  cacheDir: join(thisDir, '../../.vite'),
  plugins: [
    react({
      babel: {
        // Gets rid of deoptimization warnings for large chunks.
        // We don't need to minify here, because the output of babel
        // will get passed to esbuild anyways.
        compact: false,
        minified: false,
      },
    }),
  ],
  base: '',
  server: {
    fs: {
      strict: true,
    },
  },
  resolve: {
    preserveSymlinks: true,
  },
  optimizeDeps: {
    exclude: ['@sophie/shared'],
  },
  build: {
    target: chrome,
    assetsDir: '.',
    outDir: 'dist',
    emptyOutDir: true,
    sourcemap: isDevelopment,
    minify: !isDevelopment,
    brotliSize: false,
    rollupOptions: {
      external: ['mst-middlewares', 'remotedev', ...builtinModules],
      output: {
        banner,
      },
    },
  },
};