-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
55 lines (52 loc) · 1.43 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
import reactRefresh from "@vitejs/plugin-react-refresh";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import liveReload from "vite-plugin-live-reload";
import path from "path";
import fs from "fs";
const rootpath = "./resources/assets/scripts";
const themeDirName = path.basename(__dirname);
function getTopLevelFiles(): Record<string, string> {
let topLevelFiles = fs.readdirSync(path.resolve(__dirname, rootpath));
let files: { [key: string]: string } = {};
topLevelFiles.forEach((file) => {
const isFile = fs.lstatSync(path.resolve(rootpath, file)).isFile();
if (isFile && !file.includes(".d.ts")) {
const chunkName = file.slice(0, file.lastIndexOf("."));
files[chunkName] = path.resolve(rootpath, file);
}
});
return files;
}
export default defineConfig({
root: rootpath,
base:
process.env.APP_ENV === "development"
? "/"
: `/wp-content/themes/${themeDirName}/dist/`,
build: {
manifest: true,
emptyOutDir: true,
outDir: path.resolve(__dirname, "dist"),
assetsDir: "",
rollupOptions: {
input: getTopLevelFiles(),
},
},
server: {
// required to load scripts from custom host
cors: true,
strictPort: true,
port: 3000,
hmr: {
port: 3000,
host: "localhost",
protocol: "ws",
},
},
plugins: [
vue(),
reactRefresh(),
liveReload([`${__dirname}/**/*\.php`, "tailwind.config.js"]),
],
});