-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvite.config.mjs
More file actions
213 lines (183 loc) · 6.44 KB
/
vite.config.mjs
File metadata and controls
213 lines (183 loc) · 6.44 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import { defineConfig, loadEnv } from 'vite';
import laravel from 'laravel-vite-plugin';
import react from '@vitejs/plugin-react-swc';
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 = [];
// 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 scssDir = `resources/views/${ theme }/scss`;
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`;
// Check if scss directory exists
if ( fs.existsSync( scssDir ) ) {
try {
// Get all scss files in the directory
const findAllScssFiles = dir => {
let results = [];
const items = fs.readdirSync( dir );
for ( const item of items ) {
const fullPath = path.join( dir, item );
const stat = fs.statSync( fullPath );
if ( stat.isDirectory() ) {
results = results.concat( findAllScssFiles( fullPath ) );
} else if ( item.endsWith( '.scss' ) ) {
results.push( fullPath );
}
}
return results;
};
const scssFiles = findAllScssFiles( scssDir );
// Find duplicates (ones with and without leading underscore)
scssFiles.forEach( file => {
const filename = path.basename( file );
if ( !filename.startsWith( '_' ) ) {
const fileDir = path.dirname( file );
const underscoreVersion = `_${ filename }`;
const underscorePath = path.join( fileDir, underscoreVersion );
// Check if the underscore version exists
if ( scssFiles.includes( underscorePath ) ) {
// Remove the version without underscore
fs.unlinkSync( file );
console.log( `Removed duplicate file: ${ file }` );
}
}
} );
} catch ( error ) {
console.error( `Error processing SCSS directory ${ scssDir }:`, error );
}
}
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 );
} );
if ( fs.existsSync( 'resources/views/default/js/chatbotApp.js' ) ) {
laravelInputs.push( 'resources/views/default/js/chatbotApp.js' );
}
if ( fs.existsSync( 'resources/views/default/scss/tiptap.scss' ) ) {
laravelInputs.push( 'resources/views/default/scss/tiptap.scss' );
}
if ( fs.existsSync( 'resources/views/default/js/voiceChatbot.js' ) ) {
laravelInputs.push( 'resources/views/default/js/voiceChatbot.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 ( fs.existsSync( 'app/Extensions/Chatbot/resources/assets/scss/external-chatbot-tw.scss' ) ) {
laravelInputs.push( 'app/Extensions/Chatbot/resources/assets/scss/external-chatbot-tw.scss' );
}
if ( fs.existsSync( 'app/Extensions/ChatbotVoice/resources/assets/scss/external-chatbot-voice.scss' ) ) {
laravelInputs.push( 'app/Extensions/ChatbotVoice/resources/assets/scss/external-chatbot-voice.scss' );
}
const automationBuilderEntry = 'app/Extensions/SocialMediaAutomation/resources/assets/js/automation-builder.jsx';
if ( fs.existsSync( automationBuilderEntry ) ) {
laravelInputs.push( automationBuilderEntry );
}
const csAnnotationsEntry = 'app/Extensions/CreativeSuiteAnnotations/resources/assets/js/creative-suite-annotations.js';
if ( fs.existsSync( csAnnotationsEntry ) ) {
laravelInputs.push( csAnnotationsEntry );
}
const ugcFactoryEntry = 'app/Extensions/UGCFactory/resources/js/ugcFactory.js';
if ( fs.existsSync( ugcFactoryEntry ) ) {
laravelInputs.push( ugcFactoryEntry );
}
const ugcCreatorEntry = 'app/Extensions/UGCCreator/resources/js/ugcCreator.js';
if ( fs.existsSync( ugcCreatorEntry ) ) {
laravelInputs.push( ugcCreatorEntry );
}
if ( process.env.NODE_ENV === 'development' ) {
plugins.push( mkcert() );
}
plugins.push( react() );
plugins.push(
laravel( {
input: laravelInputs,
refresh: [ 'app/**/*.php', 'resources/views/**/*.php', 'resources/views/**/*.js' ],
} )
);
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',
'@automation': '/app/Extensions/SocialMediaAutomation/resources/assets/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.VITE_APP_URL,
headers: {
'Access-Control-Allow-Origin': '*',
'Cache-Control': 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0',
'Pragma': 'no-cache',
'Expires': '0',
},
https: true,
port: 4443,
hmr: {
host: process.env.VITE_APP_URL,
},
cors: {
origin: process.env.VITE_APP_ORIGIN ?? 'magicai.test',
credentials: true,
},
};
}
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 ),
},
};
}