3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

本番環境にてlaravel内のviteのビルドを行う

Last updated at Posted at 2023-12-01

はじめに

個人開発メモ📝
今回は、前記事に行ったherokuを使用したデプロイ作業の続きです。
前記事↓
https://qiita.com/kuro_maru/items/34bab426fdc81e4459ae

今回起きたエラー

// マニフェストが見つかりません というエラーメッセージ
Vite manifest not found at: /app/public/build/manifest.json (View: /app/resources/views/layouts/guest.blade.php) (View: /app/resources/views/layouts/guest.blade.php)

本番環境では、viteのビルドはmanifest.jsonというファイルで行われるらしく、このファイルがなかったことにより起きたエラーでした。

package.json
// ビルド情報を更新
"scripts": {
   "dev": "vite",
   "build": "vite build --mode production"
},

上記を更新したら、ターミナル上で以下を実行します。

cd プロジェクトディレクトリ
vite build --mode production

実行が完了すると、laravelプロジェクト内のpublicディレクトリ内に、新たに/build/.viteというディレクトリが生成され、その中にmanifest.jsonが生成されています。

manifest.jsonの参照先の変更

今回、ベースとなるbladeファイルにviteを読み込むような設定にしていたので、ベースのbladeファイルの記述を変更します。

resources/views/layouts/guest.blade.php
// 元々は、@vite[]の書き方をしていた箇所を以下に変更します
<!-- Fonts -->
<link rel="stylesheet" href="/build/assets/生成されたcssのファイル">

<!-- Scripts -->
<script src="/build/assets/生成されたjsファイル" type="module"></script>

このように設定をしたらエラーは消え、画面が表示されました。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?