-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
77 lines (68 loc) · 1.85 KB
/
vite.config.js
File metadata and controls
77 lines (68 loc) · 1.85 KB
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
import { defineConfig, loadEnv } from "vite";
import path from "node:path";
import fs from "node:fs";
/* Vite plugins */
import Vue from "@vitejs/plugin-vue";
import Yaml from "@rollup/plugin-yaml";
import Eslint from "@nabla/vite-plugin-eslint";
import VueI18n from "@intlify/unplugin-vue-i18n/vite";
import { visualizer as BuildVisualizer } from "rollup-plugin-visualizer";
import { Vueless, UnpluginComponents, TailwindCSS } from "vueless/plugin-vite";
/* Vite config */
export default ({ mode }) => {
// Load environment variables
process.env = {
...process.env,
...loadEnv(mode, process.cwd()),
};
return defineConfig({
plugins: [
Vue(),
Yaml(),
Eslint(),
TailwindCSS(),
Vueless(),
UnpluginComponents({ dts: false }),
VueI18n({
defaultSFCLang: "yaml",
strictMessage: false,
runtimeOnly: false,
}),
BuildVisualizer({
template: "treemap",
gzipSize: true,
brotliSize: true,
filename: "report.html",
emitFile: false,
}),
],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
...getModuleAliases(),
},
},
build: {
outDir: path.resolve(__dirname, process.env.VITE_OUTPUT_DIR || "dist"),
},
});
};
/**
* Generate vite aliases for modules.
* Converts: `./src/modules/Payments` into `#Payments`.
*/
function getModuleAliases() {
const srcDir = path.resolve(__dirname, "./src/modules");
// Check if the modules directory exists
if (!fs.existsSync(srcDir)) {
return {};
}
const folders = fs.readdirSync(srcDir).filter((name) => {
const fullPath = path.join(srcDir, name);
return fs.statSync(fullPath).isDirectory();
});
return folders.reduce((acc, folderName) => {
acc[`#${folderName}`] = path.join(srcDir, folderName);
return acc;
}, {});
}