Skip to content

Commit 77807c9

Browse files
maximejolivetclaude
andcommitted
Update vite.config.mjs
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 39b91b8 commit 77807c9

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

web/themes/custom/tailwind/vite.config.mjs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ import excludeAllCssExcept from './plugins/exclude-all-css-excepts.config.mjs';
66
import path from "path";
77
import 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

Comments
 (0)