Home > Software design >  How to deploy a Laravel Vue Vite through Apache?
How to deploy a Laravel Vue Vite through Apache?

Time:10-23

I can perfectly develop my app using:

$ php artisan serve $ npx vite

Now for the production, I did:

$ npm run build
vite v3.1.6 building for production...
✓ 420 modules transformed.
public/build/assets/logo.5cd84882.svg                 1.57 KiB
public/build/assets/laser.c7bd32d7.jpg              511.04 KiB
public/build/assets/octocat.23ab3f99.svg               1.74 KiB
public/build/assets/blueprint.96496c0c.png           555.29 KiB
public/build/assets/blueprint-big.e7d9ba70.png       711.95 KiB
public/build/manifest.json                             3.94 KiB
...

Now I was then expecting my app to be accessed from Apache. In other words, I was expecting the app.blade.php to use the static assets generated by npm run build:

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    @vite
</head>

<body >
    @inertia
</body>

</html>

However, when I access my page, I notice the @vite was replaced by:

 <script type="module" src="http://localhost:3000/@vite/client"></script>
 <link rel="stylesheet" href="http://localhost:3000/resources/css/tailwind.css" />
 <script type="module" src="http://localhost:3000/resources/scripts/main.ts"></script>

So the development is still used. Obviously, I did not change a configuration variable to say "This is the production version".

How to tell Laravel to be in production mode?

CodePudding user response:

Just change the APP_ENV variable from .env file to production and it will do the trick.

  • Related