-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvite.config.ts
More file actions
100 lines (98 loc) · 2.98 KB
/
vite.config.ts
File metadata and controls
100 lines (98 loc) · 2.98 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
import path from "path"
import { defineConfig, loadEnv } from "vite"
import sveltePreprocess from "svelte-preprocess"
export default defineConfig(async ({ mode }) => {
const isProduction = mode === "production"
const { svelte } = await import("@sveltejs/vite-plugin-svelte")
const env = loadEnv(mode, process.cwd(), "")
const backendTarget = "http://localhost:9999"
const viteRoot = path.resolve(__dirname, "src/entry")
const publicDir = path.resolve(__dirname, "src/static")
const distDir = path.resolve(__dirname, "dist")
const sourceCssPath = path.resolve(
__dirname,
"src/scss/simple-comment-style.scss"
)
const buildCssHref = "/css/simple-comment-style.css"
const styleHrefPlaceholder = "__SIMPLE_COMMENT_STYLE_HREF__"
const frontendApiUrl =
env.VITE_SIMPLE_COMMENT_API_URL ?? env.SIMPLE_COMMENT_API_URL
const frontendApiUrlDefine =
frontendApiUrl === undefined ? "undefined" : JSON.stringify(frontendApiUrl)
const toFsPath = (targetPath: string) =>
`/@fs/${targetPath.replace(/\\/g, "/")}`
const sourceCssHref = toFsPath(sourceCssPath)
return {
root: viteRoot,
publicDir,
define: {
"process.env.SIMPLE_COMMENT_API_URL": frontendApiUrlDefine,
},
plugins: [
svelte({
emitCss: false,
preprocess: [
sveltePreprocess({
typescript: { tsconfigFile: "tsconfig.frontend.json" },
}),
],
compilerOptions: { dev: !isProduction },
}),
{
name: "simple-comment-dev-html-entries",
transformIndexHtml(html, ctx) {
const styleHref = ctx?.server ? sourceCssHref : buildCssHref
return html.replaceAll(styleHrefPlaceholder, styleHref)
},
},
],
build: {
outDir: distDir,
emptyOutDir: true,
sourcemap: true,
rollupOptions: {
input: {
index: path.resolve(viteRoot, "index.html"),
icebreakers: path.resolve(viteRoot, "icebreakers/index.html"),
"simple-comment": path.resolve(__dirname, "src/simple-comment.ts"),
"simple-comment-icebreakers": path.resolve(
__dirname,
"src/simple-comment-icebreakers.ts"
),
"simple-comment-style": path.resolve(
__dirname,
"src/scss/simple-comment-style.scss"
),
},
output: {
entryFileNames: "js/[name].js",
assetFileNames: assetInfo => {
const name = assetInfo.name ?? ""
if (name.endsWith(".css")) return "css/[name][extname]"
return "assets/[name][extname]"
},
},
},
},
server: {
host: "0.0.0.0",
port: 5000,
proxy: {
"/.netlify/functions": {
target: backendTarget,
changeOrigin: true,
},
},
},
preview: {
host: "0.0.0.0",
port: 5000,
proxy: {
"/.netlify/functions": {
target: backendTarget,
changeOrigin: true,
},
},
},
}
})