-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
89 lines (85 loc) · 2.37 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
import { fileURLToPath, URL } from 'node:url'
import { join, parse, resolve } from 'node:path'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
// import VueDevTools from 'vite-plugin-vue-devtools'
import autoprefixer from 'autoprefixer'
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
export default ({ mode }: { mode: string }) => {
const env = loadEnv(mode, process.cwd())
if (mode === 'development') {
console.log(env)
}
const SocketIoProxyPath = `^${env.VITE_MIDDLELAYER_API_SOCKET_PATH}`
const ApiIiifProxyPath = [
'^',
String(env.VITE_MIDDLELAYER_API_PATH).replace(/\/+$/, ''),
'/proxy/'
].join('')
if (mode === 'development') {
console.log('SocketIoProxyPath', SocketIoProxyPath)
console.log('ApiIiifProxyPath', ApiIiifProxyPath)
}
// https://vitejs.dev/config/
return defineConfig({
plugins: [
vue(),
vueJsx(),
// VueDevTools(),
VueI18nPlugin({
compositionOnly: false,
strictMessage: false,
escapeHtml: false
})
],
css: {
postcss: {
plugins: [autoprefixer()]
}
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
proxy: {
[SocketIoProxyPath]: {
target: env.VITE_MIDDLELAYER_API,
ws: true,
changeOrigin: true
},
// this is from IIIF stored in the database, thsy usually contain /api/proxy
[ApiIiifProxyPath]: {
target: env.VITE_MIDDLELAYER_API,
ws: false,
changeOrigin: true
}
}
},
build: {
rollupOptions: {
output: {
manualChunks: id => {
if (id.includes('openseadragon')) return 'openseadragon'
if (id.includes('d3')) return 'd3'
if (id.includes('protobuf')) return 'protobuf'
if (id.includes('buffer')) return 'buffer'
}
},
input: entryPoints('index.html', 'widget/index.html')
}
}
})
}
function entryPoints(...paths: string[]) {
const entries = paths.map(parse).map(entry => {
const { dir, base, name } = entry
const key = join(dir, name)
const path = resolve(__dirname, dir, base)
return [key, path]
})
const config = Object.fromEntries(entries)
return config
}