-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
98 lines (88 loc) · 2.36 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
/* eslint-disable n/no-path-concat */
import { defineConfig, loadEnv, ServerOptions, UserConfig } from 'vite'
import { resolve } from 'node:path'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import { homedir } from 'os'
import * as fs from 'fs'
import liveReload from 'vite-plugin-live-reload'
import sassGlobImports from 'vite-plugin-sass-glob-import'
import stylelint from 'vite-plugin-stylelint'
import postcssPresetEnv from 'postcss-preset-env'
import tailwindcss from 'tailwindcss'
function detectServerConfig(host: null | string) {
const keyPath = resolve(homedir(), `.config/valet/Certificates/${host}.key`)
const certificatePath = resolve(homedir(), `.config/valet/Certificates/${host}.crt`)
if (!fs.existsSync(keyPath)) {
return {
cors: true
}
}
if (!fs.existsSync(certificatePath)) {
return {
cors: true
}
}
return {
cors: true,
hmr: { host },
host,
strictPort: true,
port: 5173,
https: {
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certificatePath)
}
}
}
// @ts-ignore
export default defineConfig(({ command, mode }) => {
const root = './wp-content/themes/socialbrothers/src'
const env = loadEnv(mode, process.cwd(), '')
const host = new URL(env.APP_URL).host
const homeDir = homedir()
let serverConfig: ServerOptions = {}
if (homeDir) {
serverConfig = detectServerConfig(host)
}
const userConfig: UserConfig = {
root,
build: {
outDir: '../dist',
emptyOutDir: true,
manifest: true,
copyPublicDir: false,
rollupOptions: {
input: [resolve(root, '/main.ts'), resolve(root, '/backend.ts')]
}
},
plugins: [
svelte({ configFile: __dirname + '/svelte.config.js' }),
sassGlobImports(),
stylelint(),
liveReload([
__dirname + '/wp-content/themes/socialbrothers/**/*.php',
__dirname + '/wp-content/themes/socialbrothers/**/*.html',
__dirname + '/wp-content/themes/socialbrothers/**/*.twig'
])
],
resolve: {
dedupe: ['svelte']
},
server: {
cors: true
},
css: {
postcss: {
plugins: [
tailwindcss,
postcssPresetEnv
]
}
}
}
userConfig.base = mode === 'development'
? '/'
: '/wp-content/themes/socialbrothers/dist'
userConfig.server = serverConfig
return userConfig
})