Ari*_*nua 22 laravel laravel-blade vite
我根据laravel给出的文档安装并配置了laravel Breeze和blade 。默认情况下它使用 Vite,但不知何故 @vite 指令在我的项目中不起作用,我不知道我错过了什么。
tailwind.config.js
const defaultTheme = require('tailwindcss/defaultTheme');
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php',
],
theme: {
extend: {
fontFamily: {
sans: ['Nunito', ...defaultTheme.fontFamily.sans],
},
},
},
plugins: [require('@tailwindcss/forms')],
};
Run Code Online (Sandbox Code Playgroud)
vite.config.js
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel([
'resources/css/app.css',
'resources/js/app.js',
]),
]
});
Run Code Online (Sandbox Code Playgroud)
然后,我使用指令创建了一个测试刀片模板@vite:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Fonts -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap">
<!-- Scripts -->
@vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
<body>
<div class="font-sans text-gray-900 antialiased">
Hello World
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我的测试路线:
Route::get('/nice', function () {
return view('test');
});
Run Code Online (Sandbox Code Playgroud)
下面的输出显示@vite没有生成适当的脚本和链接资产标签:
我的开发环境是homestead,并且我有laravel mix,因为我正在慢慢地将我们的前端升级到vite。我希望这里有人能够帮助我解决这些问题,谢谢。
小智 29
Laravel 8 文档说使用以下命令安装 laravel Breeze。
composer require laravel/breeze --dev
Run Code Online (Sandbox Code Playgroud)
但这将安装最新版本的 Breeze (^1.10),并支持 Laravel 9 Vite。由于 Laravel 8 不支持 Vite,因此您必须使用旧版本的 laravel Breeze。版本 1.9.4 适用于 Laravel 8。
因此,请尝试以下命令来安装 laravel Breeze:
composer require laravel/breeze:1.9.4
Run Code Online (Sandbox Code Playgroud)
Вит*_*тов 11
升级框架版本后,必须使用以下命令清除视图缓存:
php artisan view:clear
Run Code Online (Sandbox Code Playgroud)
那么这个新的刀片指令必须正常工作。
Laravel版本必须是^9.19使用Vite。
// composer.json
"require": {
"laravel/framework": "^9.19",
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
51536 次 |
| 最近记录: |