-
Notifications
You must be signed in to change notification settings - Fork 243
/
Copy pathvite.config.ts
138 lines (131 loc) · 4.08 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import path from "path";
import { existsSync, readFileSync } from "fs";
import { loadEnv, defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import checkerPlugin from "vite-plugin-checker";
import svgLoaderPlugin from "vite-svg-loader";
import IconsPlugin from "unplugin-icons/vite";
import packageJson from "./package.json";
import postcss from "./postcss.config.js";
import ViteGitRevisionPlugin from "./build-src/vite_git_revision_plugin";
// can't import a random file as a string :(
// importing via node_modules at least lest us sort of import it from the module rather
// than using a relative path
const lessVars = readFileSync(
"./node_modules/@si/vue-lib/src/tailwind/less_vars.less",
"utf-8",
);
// fixes dev server handling of periods in paths
// see https://github.com/vitejs/vite/issues/2415
const dotPathFixPlugin = () => ({
name: "dot-path-fix-plugin",
configureServer: (server) => {
server.middlewares.use((req, _res, next) => {
const reqPath = req.url.split("?", 2)[0];
if (
!req.url.startsWith("/@") && // virtual files provided by vite plugins
!req.url.startsWith("/api/") && // api proxy, configured below
!existsSync(`./public${reqPath}`) && // files served directly from public folder
!existsSync(`.${reqPath}`) // actual files
) {
req.url = "/";
}
next();
});
},
});
// see https://vitejs.dev/config/ for more info
export default (opts: { mode: string }) => {
// load config so we can keep the dev port to run there, and potentially other things in the future
// 3rd arg (prefix) loads all env vars instead of just VITE_APP_*
const config = loadEnv(opts.mode, process.cwd(), "");
// defineConfig is a no-op but provides typing info for the options
return defineConfig({
plugins: [
dotPathFixPlugin(),
vue(),
svgLoaderPlugin(),
// using "raw" as icon compiler (rather than `vue3`) because we need raw svgs for use in konva
// our Icon component knows how to deal with raw SVGs
IconsPlugin({ compiler: "raw" }),
process.env.NODE_ENV !== "production" &&
checkerPlugin({
vueTsc: true,
eslint: {
lintCommand: packageJson.scripts.lint,
// I _think_ we only want to pop up an error on the screen for proper errors
// otherwise we can get a lot of unused var errors when you comment something out temporarily
dev: { logLevel: ["error"] },
},
}),
ViteGitRevisionPlugin({}),
],
css: {
postcss,
preprocessorOptions: {
less: { additionalData: lessVars },
},
},
server: {
host: config.DEV_HOST,
port: parseInt(config.DEV_PORT),
strictPort: true,
fs: {
strict: true,
},
proxy: {
"/api": {
target: config.DEV_API_PROXY_URL,
ws: true,
},
},
headers: {
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'credentialless',
},
},
optimizeDeps: {
exclude: ['@sqlite.org/sqlite-wasm'],
},
preview: {
proxy: {
"/api": {
target: config.DEV_API_PROXY_URL,
ws: true,
},
},
},
resolve: {
alias: [
{
find: "@",
replacement: path.resolve(__dirname, "src"),
},
{ find: "util", replacement: "util-browser" },
],
},
build: {
manifest: "manifest.json",
rollupOptions: {
input: {
main: path.resolve(__dirname, "index.html"),
worker: path.resolve(__dirname, "src/workers/webworker.ts"), // Add worker as an entry point
},
output: {
entryFileNames: (chunk) => {
if (chunk.name === "worker") {
return "assets/webworker.js"; // Specify output path for web worker
}
return "assets/[name]-[hash].js";
},
sourcemap: "inline",
format: "es",
globals: {
react: "React",
"react-dom": "ReactDOM",
},
},
},
},
});
};