Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel vite production doesn't use https

Tags:

laravel

vite

I have laravel 10 and I'm trying to use vite to bundle my assets.

On my local machine running npm run dev works fine. But in production using npm run build doesn't use https in my blade file, so that I have mixed resources and the browser doesn't load the assets, because the rest of the page is https.

So my question is, what requirements must be set so that vite uses https and not http? Is there some ENV variables that must be set? What else could be the problem?

My vite.config.js:

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true,
        }),
    ],
    server: {
        host: true,
        hmr: {
            host: 'localhost'
        }
    },
});

package.json:

{
    "private": true,
    "scripts": {
        "dev": "vite",
        "build": "vite build"
    },
    "devDependencies": {
        "autoprefixer": "^10.4.14",
        "axios": "^1.1.2",
        "laravel-vite-plugin": "^0.7.2",
        "postcss": "^8.4.23",
        "tailwindcss": "^3.3.2",
        "vite": "^4.0.0"
    }
}

And my layout.blade.php:

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}" class="antialiased bg-gray-100">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>{{$title ?? __('TEST')}}</title>
    <link rel="shortcut icon" href="{{ asset('favicon.ico') }}">

    @vite(['resources/css/app.css', 'resources/js/app.js'])

</head>
<body>
<main>
    {{$slot}}
</main>
</body>
</html>

like image 797
C. Leo Avatar asked Sep 16 '25 12:09

C. Leo


1 Answers

You might need to set a custom ASSET_URL and set it to the https version of your URL. This worked for me in Vercel when the html was loading from https but Vite wanted to use http.

like image 168
LavAdam Avatar answered Sep 19 '25 05:09

LavAdam