forked from whimet/confluence-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
121 lines (110 loc) · 2.96 KB
/
vite.config.js
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
import path, {resolve} from 'path';
import {defineConfig, splitVendorChunkPlugin} from 'vite';
import createVuePlugin from '@vitejs/plugin-vue';
import {execSync} from "child_process";
import fs from 'fs'
import { createFilter } from '@rollup/pluginutils';
const filter = createFilter(['./drawio/**/*']);
process.env.VITE_APP_GIT_HASH = execSync('git rev-parse --short HEAD').toString().trim()
process.env.VITE_APP_GIT_BRANCH = execSync('git branch --show-current').toString().trim()
// https://stackoverflow.com/a/45993185/529187
process.env.VITE_APP_GIT_TAG = execSync('git describe --tags --always --abbrev=0').toString().trim()
console.log(`Building ${process.env.VITE_APP_GIT_TAG} (${process.env.VITE_APP_GIT_HASH}) on ${process.env.VITE_APP_GIT_BRANCH}`)
function getHtmlFiles(dir) {
const htmlFiles = [];
const files = fs.readdirSync(dir);
for (let i = 0; i < files.length; i++) {
const filepath = path.join(dir, files[i]);
if (fs.lstatSync(filepath).isFile()) {
if (path.extname(filepath) === '.html') {
htmlFiles.push(filepath);
}
}
}
return htmlFiles;
}
export default defineConfig({
build: {
rollupOptions: {
input: getHtmlFiles('./').concat(getHtmlFiles('./drawio')),
output: {
// TODO: improve the strategy
manualChunks(id) {
if (!filter(id)) {
return; // 跳过 ./drawio 下的文件
}
if ((id.includes('node_modules') && id.includes('swagger'))) {
return 'swagger'
}
if (id.includes('mermaid')) {
return 'mermaid'
}
if (id.includes('lodash')) {
return 'lodash'
}
if (id.includes('mixpanel')) {
return 'mixpanel'
}
if (id.includes('codemirror')) {
return 'codemirror'
}
if (id.includes('@zenuml/core')) {
return '@zenuml/core'
}
}
}
},
emptyOutDir: true,
},
resolve: {
alias: {
'vue': '@vue/compat',
'@': resolve(__dirname, './src')
},
},
plugins: [
splitVendorChunkPlugin(),
createVuePlugin({
template: {
compilerOptions: {
compatConfig: {
MODE: 2,
},
},
},
}),
],
test: {
environment: 'jsdom',
globals: true,
deps: {
inline: ['@vue/test-utils'],
},
},
server: {
host: '0.0.0.0',
port: 8080,
proxy: {
'/descriptor': {
target: 'http://127.0.0.1:8788/',
changeOrigin: false,
},
'/atlassian-connect-lite.json': {
target: 'http://127.0.0.1:8788/',
changeOrigin: true
},
'/installed': {
target: 'http://127.0.0.1:8788/',
changeOrigin: true
},
'/uninstalled': {
target: 'http://127.0.0.1:8788/',
changeOrigin: true
},
'/attachment': {
target: 'http://127.0.0.1:8788/',
changeOrigin: true
}
}
}
});