-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
83 lines (78 loc) · 2.01 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
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';
import fs from 'fs';
import monacoEditorPlugin from 'vite-plugin-monaco-editor';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
monacoEditorPlugin(),
Components({
resolvers: [ElementPlusResolver()]
}),
fileList()
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@topology3D': path.resolve(__dirname, './src/topology3D')
}
},
server: {
proxy: {}
},
css: {
preprocessorOptions: {
less: {
modifyVars: {
// 'primary-color': '#1890ff'
// "link-color": "#fb8501",
// "table-row-hover-bg": "#fb850103",
// "tree-node-selected-bg": "#fb850100",
},
javascriptEnabled: true
}
}
}
});
function fileList() {
return {
name: 'vite-plugin-3d-files',
configureServer(server) {
server.middlewares.use((req, res, next) => {
const { url } = req;
if (url.startsWith('/3d/') && url.endsWith('/')) {
const pwd = path.join(__dirname, 'public', url);
const files = fs.readdirSync(pwd, {
withFileTypes: true
});
const list = [];
for (const item of files) {
if (item.isDirectory()) {
list.push({ name: item.name, type: 'directory' });
} else {
list.push({ name: item.name });
}
}
res.end(JSON.stringify(list));
} else {
next();
}
});
}
};
}
function getStat(path: string) {
return new Promise((resolve, reject) => {
fs.stat(path, (err, stats) => {
if (err) {
resolve(false);
} else {
resolve(stats);
}
});
});
}