-
Notifications
You must be signed in to change notification settings - Fork 3
/
vite.config.mjs
142 lines (136 loc) · 3.31 KB
/
vite.config.mjs
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { viteStaticCopy } from 'vite-plugin-static-copy'
import * as dotenv from 'dotenv'
import { reactClickToComponent } from 'vite-plugin-react-click-to-component'
// import compression from 'vite-plugin-compression2'
import svgr from 'vite-plugin-svgr'
import { fileURLToPath, URL } from 'node:url'
import path from 'path'
dotenv.config({ path: path.join(__dirname, '.env') })
const isProduction = process.env.NODE_ENV === 'production'
const nodeEnv = isProduction ? 'production' : 'development'
/**
* @type {import('vite').UserConfig}
*/
export default defineConfig({
plugins: [
react(),
htmlPlugin(),
closePlugin(),
svgr(),
reactClickToComponent(),
viteStaticCopy({
targets: [
{
src: './src/resources',
dest: './',
},
],
}),
// compression({
// algorithm: 'gzip', exclude: [/\.(br)$ /, /\.(gz)$/],
// }),
// compression({
// algorithm: 'brotliCompress', exclude: [/\.(br)$ /, /\.(gz)$/],
// }),
],
publicDir: './src/webviews/public',
resolve: {
alias: {
lodash: 'lodash-es',
uiSrc: fileURLToPath(new URL('./src/webviews/src', import.meta.url)),
testSrc: fileURLToPath(new URL('./src/webviews/test', import.meta.url)),
},
},
server: {
port: 8080,
fs: {
allow: ['./'],
},
},
envPrefix: 'RI_',
build: {
outDir: './dist/webviews',
target: 'es2020',
minify: 'esbuild',
lib: {
entry: path.resolve(__dirname, './src/webviews/src/index.tsx'),
name: 'VSWebview',
formats: ['es'],
fileName: 'index',
},
rollupOptions: {
output: {
manualChunks: undefined,
},
},
watch: {}, // yes, this is correct
},
define: {
'process.env': isProduction ? JSON.stringify(process.platform) : {},
'process.env.NODE_ENV': `"${nodeEnv}"`,
},
// vitest testing
test: {
globals: true,
environment: 'jsdom',
testTimeout: 20000,
setupFiles: ['./src/webviews/test/setup.ts'],
coverage: {
reporter: ['text', 'html'],
reportsDirectory: './report/coverage',
include: ['src/webviews/src/**'],
exclude: [
'src/webviews/src/**/index.ts',
'src/webviews/src/**/*.d.ts',
'src/webviews/src/**/interface.ts',
],
thresholds: {
statements: 80,
lines: 80,
branches: 70,
functions: 60,
},
},
server: {
deps: {
inline: ['rawproto', 'react-monaco-editor'],
},
},
reporters: ['default', 'junit', 'html'],
outputFile: {
junit: './report/junit.xml',
html: './report/index.html',
},
},
})
// Change default route from root to our index.html
function htmlPlugin() {
return {
name: 'deep-index',
configureServer(server) {
server.middlewares.use((req, _, next) => {
req.url = req.url === '/' ? './src/webviews/index.html' : req.url
next()
})
},
}
}
// Exit from watch mode for prepublish build
function closePlugin() {
return {
name: 'ClosePlugin',
buildEnd(error) {
if (error) {
console.error(error)
process.exit(1)
}
},
closeBundle() {
if (process.env.BUILD_EXIT === 'true') {
process.exit(0)
}
},
}
}