-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvite.config.ts
More file actions
124 lines (121 loc) · 3.77 KB
/
vite.config.ts
File metadata and controls
124 lines (121 loc) · 3.77 KB
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
import { defineConfig } from "vite";
import { VitePWA } from "vite-plugin-pwa";
import importMetaUrlPlugin from "@codingame/esbuild-import-meta-url-plugin";
import * as fs from "fs";
import path from "path";
export default defineConfig({
server: {
port: 3000,
host: "0.0.0.0",
fs: {
allow: ["../"], // allow to load codicon.ttf from monaco-editor in the parent folder
},
},
build: {
target: "esnext",
emptyOutDir: false,
manifest: "manifest.json", // Generate manifest.json in outDir root for production asset resolution
},
worker: {
format: "es",
},
plugins: [
{
name: "load-vscode-css-as-string",
enforce: "pre",
async resolveId(source, importer, options) {
const resolved = await this.resolve(source, importer, options);
if (
resolved &&
resolved.id.match(
/node_modules\/(@codingame\/monaco-vscode|vscode|monaco-editor).*\.css$/,
)
) {
return {
...resolved,
id: resolved.id + "?inline",
};
}
return undefined;
},
},
{
// 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();
});
};
},
},
VitePWA({
strategies: "injectManifest",
srcDir: "src",
filename: "sw.ts",
injectRegister: false,
manifest: false,
injectManifest: {
// Precache app shell only — JS is runtime-cached (CacheFirst) since it's content-hashed
globPatterns: ["**/*.{css,html,ico,svg,woff,woff2}"],
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024,
},
devOptions: {
enabled: false,
},
}),
],
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: [
"@codingame/monaco-vscode-api/extensions",
"@codingame/monaco-vscode-api",
"@codingame/monaco-vscode-api/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: ["@electric-sql/pglite", "@postgres-language-server/wasm"],
esbuildOptions: {
tsconfig: "./tsconfig.json",
plugins: [importMetaUrlPlugin],
},
},
define: {
rootDirectory: JSON.stringify(__dirname),
},
resolve: {
dedupe: ["vscode"],
},
});