-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.mts
73 lines (71 loc) · 1.94 KB
/
vite.config.mts
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
import { fileURLToPath, URL } from "node:url";
import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";
import csp from "vite-plugin-csp-guard";
import { cjsInterop } from "vite-plugin-cjs-interop";
process.env.VITE_NONCE = Math.random().toString(36).slice(2);
// https://vitejs.dev/config/
export default defineConfig({
html: {
cspNonce: process.env.VITE_NONCE,
},
plugins: [
vue(),
csp({
dev: {
run: true,
outlierSupport: ["vue"],
},
policy: {
"style-src": ["'self'"],
"style-src-elem": ["'self'", `'nonce-${process.env.VITE_NONCE}'`],
"img-src": ["data:", "blob:"],
"script-src": ["'wasm-unsafe-eval'"],
"script-src-elem": ["https://analytics.umami.is/script.js"],
"connect-src": [
"'self'",
"https://api-gateway.umami.dev/",
"data:",
"blob:",
],
},
}),
// https://github.com/vitejs/vite/discussions/14697#discussioncomment-11170750
cjsInterop({
dependencies: ["naive-ui"],
}),
],
build: {
target: "es2022",
assetsInlineLimit: 0,
rollupOptions: {
output: {
manualChunks(id) {
// [tag-nonce]
// Naive-ui doesn't support nonce, part of logic with workaround
// Search by tag in the code
const nativeUiPath = process.cwd() + "/node_modules/naive-ui/";
if (id.startsWith(nativeUiPath)) {
return "naive-ui"; // https://github.com/tusen-ai/naive-ui/issues/6356
}
const vueUsePath = process.cwd() + "/node_modules/@vueuse/";
if (id.startsWith(vueUsePath)) {
return "@vueuse"; // only locale files, but any way
}
},
},
},
},
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
css: {
preprocessorOptions: {
scss: {
api: "modern-compiler",
},
},
},
});