I've some problems to understanding Laravel 9.x ecosystem... So, i just started with this framework and have question, how I can attach my css files into view?
I've created fresh laravel project and have maked some changes, than I've run npm run build
(because of npm run dev
stucked on my localhost URL), and after that I had in public
folder folder named build
and in this folder assets/style.0327f7a6.css
and app.334e7359.js
, but how I can include them into my template?
I tried: <link rel="stylesheet" href="{{assets('css/style.css')}}" type="text/css">
but got 404 error...
P.S I don't use mix.js(it's not included into this laravel instal, don't know why), I use vite.config.js
P.P.S I'm new into Laravel, so can anyone help me with this? I searched all google and can't find resolution for my problem...
CodePudding user response:
The assets method look at the public folder. So the {{assets('css/style.css')}}
look at the path public/css/style.css
and find nothing there. For your path you need to change your code to look at the correct path , that is {{assets('build/assets/style.0327f7a6.css')}}
CodePudding user response:
ok, so after checking some SO question I find out that now with Vite.js configuration docs we need to include all css files into app.js
file throught import
and than remove css file from vite.config.js
, after that running npm run dev
will stucked on APP_URL
, BUT it compiles all files and launched them into openned browser window!
So, after that we just need to include our files as this @vite(['resources/css/style.css', 'resources/js/app.js'])
into header and it worked!