aboutsummaryrefslogtreecommitdiffstats
path: root/packages/renderer/vite.config.js
blob: bcd19759c8ee52c17747626cae28168a3d6a7f93 (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
67
68
69
70
71
/* 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/utils.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: {
    link: [
      '@sophie/shared',
    ],
  },
  build: {
    target: chrome,
    assetsDir: '.',
    outDir: 'dist',
    emptyOutDir: true,
    sourcemap: isDevelopment,
    minify: !isDevelopment,
    brotliSize: false,
    rollupOptions: {
      external: [
        'mst-middlewares',
        'remotedev',
        ...builtinModules,
      ],
      output: {
        banner,
      },
    },
  },
};