-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
117 lines (103 loc) · 3.18 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
import { defineConfig, loadEnv } from 'vite';
import laravel from 'laravel-vite-plugin';
import fs from 'fs';
import path, { resolve } from 'path';
import { homedir } from 'os';
import mkcert from 'vite-plugin-mkcert';
const laravelInputs = [];
const themeAppJsFiles = [];
const excludedThemeDirs = [ 'vendor' ];
const plugins = [
laravel({
input: laravelInputs,
refresh: [ 'app/**/*.php', 'resources/views/**/*.php' ],
}),
];
// adding theme files
const themes = fs.readdirSync('resources/views', { withFileTypes: true })
.filter(dirent => dirent.isDirectory() && !excludedThemeDirs.includes(dirent.name))
.map(dirent => dirent.name);
themes.forEach(theme => {
const themeDashboardScssPath = `resources/views/${theme}/scss/dashboard.scss`;
const themeLPScssPath = `resources/views/${theme}/scss/landing-page.scss`;
const themeAppJsPath = `resources/views/${theme}/js/app.js`;
const chatbotAppJsPath = `resources/views/${theme}/js/chatbotApp.js`;
fs.existsSync(themeDashboardScssPath) && laravelInputs.push(themeDashboardScssPath);
fs.existsSync(themeLPScssPath) && laravelInputs.push(themeLPScssPath);
if (fs.existsSync(themeAppJsPath)) {
laravelInputs.push(themeAppJsPath);
themeAppJsFiles.push(themeAppJsPath);
}
fs.existsSync(chatbotAppJsPath) && laravelInputs.push(chatbotAppJsPath);
});
// laravelInputs.push('resources/views/default/js/chatbot/index.js');
if (fs.existsSync('resources/views/default/js/chatbotApp.js')) {
laravelInputs.push('resources/views/default/js/chatbotApp.js');
}
if (fs.existsSync('app/Extensions/Chatbot/resources/assets/scss/external-chatbot.scss')) {
laravelInputs.push('app/Extensions/Chatbot/resources/assets/scss/external-chatbot.scss');
}
if ( process.env.NODE_ENV === 'development' ) {
plugins.push(mkcert());
}
export default ({ mode }) => {
// Load app-level env vars to node-level env vars.
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
return defineConfig({
server: detectServerConfig(process.env.VITE_APP_DOMAIN || 'magicai.test'),
plugins,
build: {
rollupOptions: {
output: {
entryFileNames: 'assets/[name]-[hash].js',
chunkFileNames: 'assets/[name]-[hash].js',
assetFileNames: 'assets/[name]-[hash].[ext]',
// manualChunks: {
// All files will be bundled into a single file
// 'app': themeAppJsFiles
// }
}
}
},
resolve: {
alias: {
'@': '/resources/js',
'@public': '/public',
'@themeAssets': '/public/themes',
'~nodeModules': path.resolve(__dirname, 'node_modules'),
'~vendor': path.resolve(__dirname, 'vendor'),
}
}
});
};
function detectServerConfig(domain) {
if (process.env.NODE_ENV === 'development') {
return {
host: domain,
origin: process.env.APP_URL,
https: true,
port: 4443,
hmr: {
host: process.env.APP_URL,
},
};
}
let keyPath = resolve(homedir(), `.config/valet/Certificates/${domain}.key`);
let certPath = resolve(homedir(), `.config/valet/Certificates/${domain}.crt`);
if (!fs.existsSync(keyPath)) {
return {};
}
if (!fs.existsSync(certPath)) {
return {};
}
return {
hmr: {
host: domain,
},
host: domain,
https: {
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certPath),
},
};
}