@@ -6,9 +6,13 @@ import excludeAllCssExcept from './plugins/exclude-all-css-excepts.config.mjs';
66import path from "path" ;
77import fs from 'fs' ;
88
9- export default defineConfig ( ( { mode} ) => {
9+ export default defineConfig ( ( { mode, command } ) => {
1010 const env = loadEnv ( mode , path . resolve ( __dirname , "../../../.." ) , "" ) ;
1111
12+ const keyPath = path . resolve ( __dirname , 'plugins/https_key/localhost-key.pem' ) ;
13+ const certPath = path . resolve ( __dirname , 'plugins/https_key/localhost.pem' ) ;
14+ const hasHttpsCerts = fs . existsSync ( keyPath ) && fs . existsSync ( certPath ) ;
15+
1216 return {
1317 plugins : [
1418 tailwindcss ( ) ,
@@ -43,10 +47,10 @@ export default defineConfig(({mode}) => {
4347
4448 server : {
4549 host : true , // Listen on all interfaces
46- https : { // Enable HTTPS with self-signed certificate
47- key : fs . readFileSync ( './plugins/https_key/localhost-key.pem' ) ,
48- cert : fs . readFileSync ( './plugins/https_key/localhost.pem' ) ,
49- } ,
50+ https : command === 'serve' && hasHttpsCerts ? { // Enable HTTPS with self-signed certificate, when available
51+ key : fs . readFileSync ( keyPath ) ,
52+ cert : fs . readFileSync ( certPath ) ,
53+ } : undefined ,
5054 origin : env . VITE_SERVER_ORIGIN , // Dev server origin for HMR
5155 cors : {
5256 origin : [ 'https://localhost:3009' , env . VITE_SERVER_ORIGIN ] , // Allow CORS for the specified origin
0 commit comments