-
Notifications
You must be signed in to change notification settings - Fork 9
/
vite.config.mts
117 lines (112 loc) · 4.11 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import basicSsl from '@vitejs/plugin-basic-ssl'
import vue from '@vitejs/plugin-vue'
import gitDescribe from 'git-describe'
import { dirname, resolve } from 'path'
import { fileURLToPath, URL } from 'url'
import { defineConfig, normalizePath } from 'vite'
import { viteStaticCopy } from 'vite-plugin-static-copy'
import generateBuildInfo from './vite-plugins/vite-plugin-generate-build-info'
// We take the version from APP_VERSION but if not set, then take
// it from git describe command
let appVersion = process.env.APP_VERSION
if (!appVersion) {
// NOTE: git-describe package add sometimes `+` signs (what the real git describe command don't)
// and the `+` sign on the URL is actually a space, so it should be percent encoded.
// Therefore we change the + sign into '-' for simplification.
appVersion = 'v' + gitDescribe.gitDescribeSync().semverString.replace('+', '-')
}
const __dirname = dirname(fileURLToPath(import.meta.url))
const cesiumSource = `${__dirname}/node_modules/cesium/Source`
const cesiumWorkers = '../Build/Cesium/Workers'
/**
* We use manual chunks to reduce the size of the final index.js file to improve startup
* performance.
*
* @param id
* @returns
*/
function manualChunks(id) {
// Put all files from the src/utils into the chunk named utils.js
if (id.includes('/src/utils/')) {
return 'utils'
}
}
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
return {
base: './',
build: {
emptyOutDir: true,
assetsDir: `${appVersion}/assets`,
outDir: `./dist/${mode}`,
rollupOptions: {
output: {
manualChunks,
},
},
},
plugins: [
{
...(process.env.USE_HTTPS
? basicSsl({
/** Name of certification */
name: 'localhost',
/** Custom trust domains */
domains: ['localhost', '192.168.*.*'],
/** Custom certification directory */
certDir: './devServer/cert',
})
: {}),
apply: 'serve',
},
vue({
isProduction: mode === 'production',
template: {
compilerOptions: {
isCustomElement: (tag) => tag === 'cesium-compass',
},
},
}),
generateBuildInfo(appVersion),
// CesiumJS requires static files from the following 4 folders to be included in the build
// https://cesium.com/learn/cesiumjs-learn/cesiumjs-quickstart/#install-with-npm
viteStaticCopy({
targets: [
{
src: normalizePath(`${cesiumSource}/${cesiumWorkers}`),
dest: `./`,
},
{
src: normalizePath(`${cesiumSource}/Assets/`),
dest: `./`,
},
{
src: normalizePath(`${cesiumSource}/Widgets/`),
dest: `./`,
},
{
src: normalizePath(`${cesiumSource}/ThirdParty/`),
dest: `./`,
},
],
}),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
tests: fileURLToPath(new URL('./tests', import.meta.url)),
cesium: normalizePath(resolve(__dirname, 'node_modules/cesium')),
},
},
define: {
__APP_VERSION__: JSON.stringify(appVersion),
VITE_ENVIRONMENT: JSON.stringify(mode),
},
test: {
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
reporter: ['default', 'junit'],
outputFile: 'tests/results/unit/unit-test-report.xml',
silent: true,
},
}
})