-
Notifications
You must be signed in to change notification settings - Fork 37
/
vite.config.ts
80 lines (77 loc) · 2.7 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
import { defineConfig } from 'vite'
import importMetaUrlPlugin from '@codingame/esbuild-import-meta-url-plugin'
import * as fs from 'fs'
import path from 'path'
import pkg from './package.json' assert { type: 'json' }
const localDependencies = Object.entries(pkg.dependencies).filter(([, version]) => version.startsWith('file:../')).map(([name]) => name)
export default defineConfig({
build: {
target: 'esnext'
},
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, import.meta.url).pathname
if (pathname.endsWith('.html')) {
res.setHeader('Content-Type', 'text/html')
res.writeHead(200)
res.write(fs.readFileSync(path.join(__dirname, pathname)))
res.end()
}
}
next()
})
}
}
}
],
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'
],
exclude: [],
esbuildOptions: {
tsconfig: './tsconfig.json',
plugins: [importMetaUrlPlugin]
}
},
server: {
port: 5173,
host: '0.0.0.0',
fs: {
allow: ['../'] // allow to load codicon.ttf from monaco-editor in the parent folder
}
},
define: {
rootDirectory: JSON.stringify(__dirname)
},
resolve: {
dedupe: ['vscode', ...localDependencies]
}
})