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
  | 
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
import checkerPlugin from "vite-plugin-checker";
import istanbul from "vite-plugin-istanbul";
import svgr from "vite-plugin-svgr";
import tsconfigPaths from "vite-tsconfig-paths";
export default defineConfig(({ mode }) => {
    const isCoverage = process.env.VITE_COVERAGE === "true";
    const sourcemap = isCoverage ? "inline" : undefined;
    const istanbulPlugin = isCoverage
        ? istanbul({
              checkProd: false,
              exclude: ["node_modules"],
              extension: [".js", ".jsx", ".ts", ".tsx"],
              forceBuildInstrument: true,
              include: "src/*",
              requireEnv: true,
          })
        : undefined;
    return {
        base: "./",
        build: {
            assetsDir: "static",
            emptyOutDir: true,
            outDir: "../internal/server/public_html",
            rollupOptions: {
                output: {
                    assetFileNames: ({ name }) => {
                        if (name && name.endsWith(".css")) {
                            return "static/css/[name].[hash].[ext]";
                        }
                        return "static/media/[name].[hash].[ext]";
                    },
                    chunkFileNames: (chunkInfo) => {
                        switch (chunkInfo.name) {
                            case "index":
                                return `static/js/[name].[hash].js`;
                            default:
                                if (chunkInfo.moduleIds.length === 0) {
                                    return `static/js/[name].[hash].js`;
                                }
                                const last = chunkInfo.moduleIds[chunkInfo.moduleIds.length - 1];
                                if (last.includes("@mui/")) {
                                    return `static/js/mui.[name].[hash].js`;
                                }
                                const match = last.match(/authelia\/web\/src\/([a-zA-Z]+)\/([a-zA-Z]+)/);
                                if (match) {
                                    switch (match[2]) {
                                        case "LoginPortal":
                                            return `static/js/portal.[name].[hash].js`;
                                        case "ResetPassword":
                                            return `static/js/reset-password.[name].[hash].js`;
                                        case "Settings":
                                            switch (chunkInfo.name) {
                                                case "SettingsRouter":
                                                    return `static/js/settings.router.[hash].js`;
                                                default:
                                                    return `static/js/settings.[name].[hash].js`;
                                            }
                                        default:
                                            switch (chunkInfo.name) {
                                                case "LoginLayout":
                                                    return `static/js/${match[1]}.Login.[hash].js`;
                                                case "MinimalLayout":
                                                    return `static/js/${match[1]}.Minimal.[hash].js`;
                                                default:
                                                    return `static/js/${match[1]}.[name].[hash].js`;
                                            }
                                    }
                                }
                                return `static/js/[name].[hash].js`;
                        }
                    },
                    entryFileNames: `static/js/[name].[hash].js`,
                },
            },
            sourcemap,
        },
        optimizeDeps: {
            include: ["@emotion/react", "@emotion/styled"],
        },
        server: {
            open: false,
            port: 3000,
            allowedHosts: ["login.example.com"],
        },
        test: {
            coverage: {
                provider: "istanbul",
            },
            environment: "happy-dom",
            globals: true,
            onConsoleLog() {
                return false;
            },
            setupFiles: ["src/setupTests.ts"],
        },
        plugins: [
            checkerPlugin({ eslint: { lintCommand: "eslint . --ext .js,.jsx,.ts,.tsx" }, typescript: true }),
            istanbulPlugin,
            react(),
            svgr(),
            tsconfigPaths(),
        ],
    };
});
  |