forked from frappe/hrms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
127 lines (123 loc) · 2.86 KB
/
vite.config.js
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
import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import { VitePWA } from "vite-plugin-pwa"
import frappeui from "frappe-ui/vite"
import path from "path"
import fs from "fs"
export default defineConfig({
server: {
port: 8080,
proxy: getProxyOptions(),
},
plugins: [
vue(),
frappeui(),
VitePWA({
registerType: "autoUpdate",
strategies: "injectManifest",
injectRegister: null,
devOptions: {
enabled: true,
},
manifest: {
display: "standalone",
name: "Frappe HR",
short_name: "Frappe HR",
start_url: "/hrms",
description: "Everyday HR & Payroll operations at your fingertips",
theme_color: "#ffffff",
icons: [
{
src: "/assets/hrms/manifest/manifest-icon-192.maskable.png",
sizes: "192x192",
type: "image/png",
purpose: "any",
},
{
src: "/assets/hrms/manifest/manifest-icon-192.maskable.png",
sizes: "192x192",
type: "image/png",
purpose: "maskable",
},
{
src: "/assets/hrms/manifest/manifest-icon-512.maskable.png",
sizes: "512x512",
type: "image/png",
purpose: "any",
},
{
src: "/assets/hrms/manifest/manifest-icon-512.maskable.png",
sizes: "512x512",
type: "image/png",
purpose: "maskable",
},
],
},
}),
],
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
},
build: {
outDir: "../hrms/public/frontend",
emptyOutDir: true,
target: "es2015",
commonjsOptions: {
include: [/tailwind.config.js/, /node_modules/],
},
sourcemap: true,
rollupOptions: {
output: {
manualChunks: {
"frappe-ui": ["frappe-ui"],
},
},
},
},
optimizeDeps: {
include: [
"frappe-ui > feather-icons",
"showdown",
"tailwind.config.js",
"engine.io-client",
],
},
})
function getProxyOptions() {
const config = getCommonSiteConfig()
const webserver_port = config ? config.webserver_port : 8000
if (!config) {
console.log("No common_site_config.json found, using default port 8000")
}
return {
"^/(app|login|api|assets|files|private)": {
target: `http://127.0.0.1:${webserver_port}`,
ws: true,
router: function (req) {
const site_name = req.headers.host.split(":")[0]
console.log(`Proxying ${req.url} to ${site_name}:${webserver_port}`)
return `http://${site_name}:${webserver_port}`
},
},
}
}
function getCommonSiteConfig() {
let currentDir = path.resolve(".")
// traverse up till we find frappe-bench with sites directory
while (currentDir !== "/") {
if (
fs.existsSync(path.join(currentDir, "sites")) &&
fs.existsSync(path.join(currentDir, "apps"))
) {
let configPath = path.join(currentDir, "sites", "common_site_config.json")
if (fs.existsSync(configPath)) {
return JSON.parse(fs.readFileSync(configPath))
}
return null
}
currentDir = path.resolve(currentDir, "..")
}
return null
}