-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.ts
88 lines (82 loc) · 2.02 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
// vite.config.js
import { defineConfig } from 'vite';
import { fileURLToPath } from 'node:url';
import usePHP from 'vite-plugin-php';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import { ViteEjsPlugin } from 'vite-plugin-ejs';
import { imagetools } from 'vite-imagetools';
import { existsSync } from 'node:fs';
export default defineConfig(({ command }) => {
const publicBasePath = '/php-vite-starter/'; // Change if deploying under a nested public path. Needs to end with a /. See https://vitejs.dev/guide/build.html#public-base-path
const base = command === 'serve' ? '/' : publicBasePath;
const BASE = base.substring(0, base.length - 1);
return {
base,
plugins: [
imagetools(),
usePHP({
entry: [
'index.php',
'configs/env.php',
'pages/**/*.php',
'partials/**/*.php',
],
rewriteUrl(requestUrl) {
const filePath = fileURLToPath(
new URL('.' + requestUrl.pathname, import.meta.url),
);
const publicFilePath = fileURLToPath(
new URL(
'./public' + requestUrl.pathname,
import.meta.url,
),
);
if (
!requestUrl.pathname.includes('.php') &&
(existsSync(filePath) || existsSync(publicFilePath))
) {
return undefined;
}
requestUrl.pathname = 'index.php';
return requestUrl;
},
}),
ViteEjsPlugin({
BASE,
}),
viteStaticCopy({
targets: [
{ src: 'public', dest: '' },
{ src: 'system', dest: '' },
{ src: 'configs', dest: '', overwrite: false },
{ src: 'vendor', dest: '' },
],
silent: command === 'serve',
}),
],
define: {
'BASE': JSON.stringify(BASE),
'import.meta.env.BASE': JSON.stringify(BASE),
},
resolve: {
alias: {
'~/': fileURLToPath(new URL('./src/', import.meta.url)),
},
},
publicDir: command === 'build' ? 'raw' : 'public',
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
},
},
},
server: {
port: 3000,
},
build: {
assetsDir: 'public',
emptyOutDir: true,
},
};
});