-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
114 lines (106 loc) · 3.6 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
import path from "path"
import {defineConfig} from "vite"
import {svelte} from "@sveltejs/vite-plugin-svelte"
import sveltePreprocess from "svelte-preprocess"
import copy from "rollup-plugin-copy"
import {createHtmlPlugin} from "vite-plugin-html"
import projectAliases from "./project-aliases.json" with { type: "json" }
const isProduction = process.env.NODE_ENV === "production"
console.log("IS PRODUCTION BUILD: ", isProduction)
const outRootDir = "__build"
const baseUrl = "/admin"
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
svelte({
preprocess: sveltePreprocess()
}),
// copy files that are not frequently modified (for other assets create separate copy plugin)
copy({
targets: [
{
src: "node_modules/jsoneditor/dist/img/jsoneditor-icons.svg",
dest: outRootDir + "/images"
},
{
src: "node_modules/jquery/dist/jquery.min.js",
dest: outRootDir + "/js"
},
{
src: "node_modules/jquery-ui-dist/jquery-ui.min.js",
dest: outRootDir + "/js"
},
{
src: "node_modules/jquery-ui-dist/jquery-ui.min.css",
dest: outRootDir + "/css"
},
{
src: "node_modules/@fortawesome/fontawesome-free/webfonts",
dest: outRootDir
}
]
}) as any, // this is needed because of a error in vite-plugin-copy type
// this config will copy assets into the root of build output (given that the build output is /admin)
// viteStaticCopy({
// targets: [
// {src: "node_modules/jsoneditor/dist/img/jsoneditor-icons.svg", dest: "../images"},
// // {src: "node_modules/bootstrap/dist/js/bootstrap.bundle.min.js", dest: outRootDir + "/js"},
// // {src: "node_modules/admin-lte/dist/js/adminlte.min.js", dest: outRootDir + "/js"},
// {src: "node_modules/jquery/dist/jquery.min", dest: "../js"},
// {src: "node_modules/jquery-ui-dist/jquery-ui.min.js", dest: "../js"},
// {src: "node_modules/jquery-ui-dist/jquery-ui.min.css", dest: "../css"},
// {src: "node_modules/@fortawesome/fontawesome-free/webfonts", dest: "../"},
// {src: "public/*", dest: "../"}
// ]
// }),
createHtmlPlugin({
entry: "src/main.js",
minify: isProduction,
inject: {
data: {
contextPlaceholders:
(isProduction &&
`<input id="languages" type="hidden" value="{LANGS}">
<input id="current-user" type="hidden" value="{CURRENT_USER}">
<input id="socket-token" type="hidden" value="{SOCKET_TOKEN}">
<input id="session-timeout" type="hidden" value="{SESSION_TIMEOUT}">
<input id="current-locale" type="hidden" value="{CURRENT_LOCALE}">`) ||
""
}
}
})
],
resolve: {
alias: Object.entries(projectAliases)
.map(([alias, aliasPath]) => {
return {find: alias, replacement: path.join(__dirname, ...aliasPath)}
})
},
optimizeDeps: {
include: ["toastr", "inputmask", "jquery"]
},
// publicDir: false, // !isProduction && outRootDir,
base: baseUrl,
// server: {
// host: !isProduction && "localhost" || "",
// port: 5173,
// strictPort: true
// },
build: {
// assetsDir: "../",
outDir: outRootDir + "/admin",
// copyPublicDir: false
// emptyOutDir: true
},
// working (should be - it is experimental..)
// experimental: {
// // to fix links in index.html that are served from shared place in the root of serve dir
// renderBuiltUrl(filename, {hostId, hostType, type}) {
// if (type === "public") {
// return "/" + filename
// } else {
// return baseUrl + "/" + filename
// }
// }
// }
})