aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/vite.config.ts
blob: fbae83c88bc23dca6fd0867671a559a55f44d53b (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* eslint-disable camelcase */

/// <reference types="vitest" />
/// <reference types="vite/client" />
/// <reference types="node" />

import react from "@vitejs/plugin-react";
import path from "path";
import { defineConfig, loadEnv } from "vite";
import checker from "vite-plugin-checker";
import { VitePWA } from "vite-plugin-pwa";
import chunks from "./config/chunks";
import overrideEnv from "./config/configReader";

export default defineConfig(async ({ mode, command }) => {
  const env = loadEnv(mode, process.cwd());

  if (command === "serve") {
    await overrideEnv(env);
  }

  const target = env.VITE_PROXY_URL;
  const ws = env.VITE_ALLOW_WEBSOCKET === "true";
  const secure = env.VITE_PROXY_SECURE === "true";

  const imagesFolder = mode === "development" ? "public/images" : "images";

  return {
    plugins: [
      react(),
      checker({
        typescript: true,
        eslint: {
          lintCommand: "eslint --ext .ts,.tsx src",
        },
        enableBuild: false,
      }),
      VitePWA({
        workbox: {
          globIgnores: ["index.html"],
        },
        registerType: "autoUpdate",
        includeAssets: [
          `${imagesFolder}/favicon.ico`,
          `${imagesFolder}/apple-touch-icon-180x180.png`,
        ],
        manifest: {
          name: "Bazarr",
          short_name: "Bazarr",
          description:
            "Bazarr is a companion application to Sonarr and Radarr. It manages and downloads subtitles based on your requirements.",
          theme_color: "#be4bdb",
          icons: [
            {
              src: `${imagesFolder}/pwa-64x64.png`,
              sizes: "64x64",
              type: "image/png",
            },
            {
              src: `${imagesFolder}/pwa-192x192.png`,
              sizes: "192x192",
              type: "image/png",
            },
            {
              src: `${imagesFolder}/pwa-512x512.png`,
              sizes: "512x512",
              type: "image/png",
            },
          ],
          screenshots: [
            {
              src: `/${imagesFolder}/pwa-wide-series-list.jpeg`,
              sizes: "1447x1060",
              label: "Series List",
              form_factor: "wide",
              type: "image/jpeg",
            },
            {
              src: `/${imagesFolder}/pwa-wide-series-overview.jpeg`,
              sizes: "1447x1060",
              label: "Series Overview",
              form_factor: "wide",
              type: "image/jpeg",
            },
            {
              src: `/${imagesFolder}/pwa-narrow-series-list.jpeg`,
              sizes: "491x973",
              label: "Series List",
              form_factor: "narrow",
              type: "image/jpeg",
            },
            {
              src: `/${imagesFolder}/pwa-narrow-series-overview.jpeg`,
              sizes: "491x973",
              label: "Series Overview",
              form_factor: "narrow",
              type: "image/jpeg",
            },
          ],
        },
        devOptions: {
          enabled: mode === "development",
        },
      }),
    ],
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `
            @import "./src/assets/_mantine";
            @import "./src/assets/_bazarr";
          `,
        },
      },
    },
    base: "./",
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "./src"),
      },
    },
    build: {
      manifest: true,
      sourcemap: mode === "development",
      outDir: "./build",
      rollupOptions: {
        output: {
          manualChunks: chunks,
        },
      },
    },
    test: {
      globals: true,
      environment: "jsdom",
      setupFiles: "./src/tests/setup.ts",
    },
    server: {
      proxy: {
        "^/(api|images|test|bazarr.log)/.*": {
          target,
          changeOrigin: true,
          secure,
          ws,
        },
      },
      host: true,
      open: "/",
    },
  };
});