-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.mts
93 lines (89 loc) · 2.5 KB
/
vite.config.mts
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
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite';
import Vue from '@vitejs/plugin-vue';
import * as child from 'child_process';
import path from 'path';
import AutoImport from 'unplugin-auto-import/vite';
import { HeadlessUiResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';
import { VueRouterAutoImports } from 'unplugin-vue-router';
import VueRouter from 'unplugin-vue-router/vite';
import { defineConfig } from 'vite';
import { ViteMinifyPlugin } from 'vite-plugin-minify';
import Layouts from 'vite-plugin-vue-layouts';
const commitHash = child.execSync('git rev-parse --short HEAD').toString().trim();
export default defineConfig({
define: {
__COMMIT_HASH__: JSON.stringify(commitHash)
},
plugins: [
AutoImport({
imports: [
'vue',
'vue-i18n',
'@vueuse/core',
'@vueuse/head',
'pinia',
VueRouterAutoImports,
{
'vue-router/auto': ['createRouter', 'createWebHistory']
},
{
from: 'vue-router/auto',
imports: ['RouteRecordRaw'],
type: true
}
]
}),
VueI18nPlugin({
include: [path.resolve(__dirname, './src/locales/**/*.json')]
}),
VueRouter({}),
Vue({
include: [/\.vue$/, /\.md$/]
}),
Components({
extensions: ['vue', 'md'],
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
directoryAsNamespace: true,
collapseSamePrefixes: true,
resolvers: [
HeadlessUiResolver({ prefix: 'Hui' }),
{
type: 'component',
resolve: (name) => {
if (name === 'AgGridVue') {
return { name: 'AgGridVue', from: 'ag-grid-vue3' };
}
}
}
]
}),
Layouts(),
{
name: 'vue-auto-component-name',
transform(code, id) {
if (!id.endsWith('.vue')) {
return;
}
let path = id.replace(__dirname, '');
let rpath;
if (path.startsWith('/src/components')) {
rpath = path.replace('/src/components/', '');
} else if (path.startsWith('/src/pages')) {
rpath = path.replace('/src/pages/', '');
}
if (rpath) {
let componentName = rpath.replace('.vue', '').replace(/\//g, '-');
code += '\n_sfc_main.name="' + componentName + '"';
return code;
}
}
},
ViteMinifyPlugin()
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src')
}
}
});