This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
107 lines (98 loc) · 2.74 KB
/
vite.config.ts
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
import path from "path";
import { RollupOptions } from "rollup";
import {
UserConfig,
CSSOptions,
ConfigEnv,
defineConfig,
BuildOptions,
PreviewOptions,
PluginOption,
ServerOptions,
} from "vite";
import react from "@vitejs/plugin-react-swc";
import eslint from "vite-plugin-eslint";
import basicSsl from "@vitejs/plugin-basic-ssl";
import legacy from "@vitejs/plugin-legacy";
const DEVELOPMENT_MODE = "development";
/**
* Docs: https://vitejs.dev/
* Make sure to check https://github.com/vitejs/awesome-vite for cool stuff
*/
export default defineConfig(
async ({ command, mode }: ConfigEnv): Promise<UserConfig> => {
const HTTPS = process.env.HTTPS === "true";
const HOST = HTTPS ? "127.0.0.1" : "localhost";
const rollupOptions: RollupOptions = {
input: {
main: path.resolve(__dirname, "src", "index.html"),
day: path.resolve(__dirname, "src", "styles", "themes", "day.scss"),
night: path.resolve(__dirname, "src", "styles", "themes", "night.scss"),
},
output: {
manualChunks: {
react: ["react", "react-dom"],
agGrid: ["ag-grid-react"],
},
// rollup adds hash version id to a filename of each artefact, we need to disable it due the deployment configuration
entryFileNames: `[name].js`,
chunkFileNames: `[name].js`,
assetFileNames: `assets/[name].[ext]`,
},
};
const cssOptions: CSSOptions = {
preprocessorOptions: {
scss: {
sourceMapEmbed: true,
},
},
};
const buildOptions: BuildOptions = {
outDir: path.join(process.cwd(), "dist"),
emptyOutDir: true, // clean up the previously built assets before the next build
minify: "terser",
terserOptions: {},
cssMinify: true,
sourcemap: mode === DEVELOPMENT_MODE ? "inline" : false,
rollupOptions: rollupOptions,
};
const serverOptions: ServerOptions = {
port: 3000,
https: HTTPS,
host: HOST,
watch: {
interval: 1000,
},
};
const previewOptions: PreviewOptions = {
port: 3001,
host: HOST,
https: HTTPS,
};
const pluginsList: PluginOption[] = [
eslint({
failOnError: true,
emitWarning: true,
}),
react(),
legacy({
targets: "last 10 versions, not dead",
}),
];
if (HTTPS) {
pluginsList.push(basicSsl());
}
return Promise.resolve({
root: path.join(process.cwd(), "src"),
envDir: path.resolve(__dirname, "env"),
css: cssOptions,
build: buildOptions,
server: serverOptions,
preview: previewOptions,
plugins: pluginsList,
define: {
VITE_USER_DYNAMIC: Math.random() > 0.5,
},
});
}
);