-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
115 lines (111 loc) · 3.51 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
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
import { defineConfig } from 'vite'
import importMetaUrlPlugin from '@codingame/esbuild-import-meta-url-plugin'
import tsconfigPaths from 'vite-tsconfig-paths'
import * as fs from 'fs'
import path from 'path'
import dynamicImport from 'vite-plugin-dynamic-import'
import vsixPlugin from '@codingame/monaco-vscode-rollup-vsix-plugin'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
const pkg = JSON.parse(
fs.readFileSync(new URL('./package.json', import.meta.url)).toString()
)
const localDependencies = Object.entries(pkg.dependencies as Record<string, string>)
.filter(([, version]) => version.startsWith('file:../'))
.map(([name]) => name)
export default defineConfig({
build: {
target: 'esnext'
},
worker: {
format: 'es'
},
plugins: [
{
// For the *-language-features extensions which use SharedArrayBuffer
name: 'configure-response-headers',
apply: 'serve',
configureServer: (server) => {
server.middlewares.use((_req, res, next) => {
res.setHeader('Cross-Origin-Embedder-Policy', 'credentialless')
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin')
res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin')
next()
})
}
},
{
name: 'force-prevent-transform-assets',
apply: 'serve',
configureServer(server) {
return () => {
server.middlewares.use(async (req, res, next) => {
if (req.originalUrl != null) {
const pathname = new URL(req.originalUrl, 'http://dummy').pathname
if (pathname.endsWith('.html')) {
res.setHeader('Content-Type', 'text/html')
res.writeHead(200)
console.log("-> serving", pathname)
// check if the file exists
const filePath = path.join('.', pathname)
if (fs.existsSync(filePath)) {
res.write(fs.readFileSync(filePath))
} else {
res.write("File not found")
}
res.end()
}
}
next()
})
}
}
},
tsconfigPaths(),
dynamicImport(),
vsixPlugin(),
tailwindcss(),
react()
],
esbuild: {
minifySyntax: false
},
optimizeDeps: {
// This is require because vite excludes local dependencies from being optimized
// Monaco-vscode-api packages are local dependencies and the number of modules makes chrome hang
include: [
// add all local dependencies...
...localDependencies,
// and their exports
'vscode/extensions',
'vscode/services',
'vscode/monaco',
'vscode/localExtensionHost',
// These 2 lines prevent vite from reloading the whole page when starting a worker (so 2 times in a row after cleaning the vite cache - for the editor then the textmate workers)
// it's mainly empirical and probably not the best way, fix me if you find a better way
'vscode-textmate',
'vscode-oniguruma',
'@vscode/vscode-languagedetection',
'marked'
],
exclude: [],
esbuildOptions: {
tsconfig: './tsconfig.json',
plugins: [importMetaUrlPlugin]
}
},
server: {
port: 5173,
host: '0.0.0.0',
headers: {
"cross-origin-opener-policy": "same-origin",
"cross-origin-embedder-policy": "credentialless",
}
},
define: {
rootDirectory: JSON.stringify(__dirname)
},
resolve: {
dedupe: ['vscode', ...localDependencies]
}
})