-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
162 lines (127 loc) · 3.42 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
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
151
152
153
154
155
156
157
158
159
160
161
162
/*
* This file is part of prose-pod-dashboard
*
* Copyright 2024, Prose Foundation
*/
/**************************************************************************
* IMPORTS
* ************************************************************************* */
import fs from "fs";
import path from "path";
import merge from "lodash.merge";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import commonConfig from "./config/common";
import developmentConfig from "./config/development";
import productionConfig from "./config/production";
/**************************************************************************
* INTERFACES
* ************************************************************************* */
interface Configuration {
environment: string;
api: {
version: string;
endpoint: {
local: string;
remote: string;
};
};
}
/**************************************************************************
* CONSTANTS
* ************************************************************************* */
const ASSETS_ICONS_PATH = path.join(__dirname, "src/assets/icons/");
/**************************************************************************
* CONFIGURATION
* ************************************************************************* */
const CONFIG: Configuration = (function () {
// Initialize empty configuration
const config = {
environment: "",
api: {
version: "",
endpoint: {
local: "",
remote: ""
}
}
};
// Merge common configuration
merge(config, commonConfig);
// Merge per-environment configuration
switch (process.env.NODE_ENV) {
case "production": {
merge(config, productionConfig);
break;
}
default: {
merge(config, developmentConfig);
}
}
// Merge local configuration? (if any)
try {
const localConfig = JSON.parse(
fs.readFileSync("./config/local.json", "utf8")
);
merge(config, localConfig);
} catch (_) {
// Ignore errors (local configuration not found)
}
return config;
})();
/**************************************************************************
* EXPORTS
* ************************************************************************* */
export default defineConfig({
logLevel: "info",
server: {
host: "localhost",
port: 3030,
strictPort: true,
proxy: {
[`${CONFIG.api.endpoint.local}/`]: {
target: CONFIG.api.endpoint.remote,
rewrite: targetUrl => {
const localUrl = CONFIG.api.endpoint.local;
if (targetUrl.startsWith(`${localUrl}/`) === true) {
return targetUrl.replace(localUrl, "");
}
return targetUrl;
}
}
}
},
preview: {
host: "localhost",
port: 3040,
strictPort: true
},
resolve: {
alias: [{ find: "@/", replacement: path.join(__dirname, "src/") }]
},
plugins: [
vue(),
createSvgIconsPlugin({
iconDirs: [ASSETS_ICONS_PATH],
symbolId: "icon-[name]",
inject: "body-last",
customDomId: "__svg__icons__"
})
],
css: {
devSourcemap: false,
preprocessorOptions: {
scss: {
additionalData: `
@import "@/assets/stylesheets/variables/all.scss";
@import "@/assets/stylesheets/tools/all.scss";
`
}
},
postcss: {}
},
define: {
__CONFIG__: CONFIG
}
});