Vite on Laravel Forge running npm run dev - laravel

We would like to create a dev environment in laravel forge. The site is working correctly, but when we run npm run dev it won't load CSS and assets.
How can we configure Nginx on laravel forge and Vite to work with dev environment?
We tried using --host parameter on npm run dev, but still not working.

Related

laravel showing error when vite not loaded (how to start larvel just with php artisan serve)

I am new to Laravel and I start my Laravel project using php artisan serve but I found that I also have to load Vite from another command prompt using npm run dev in order to make Laravel project run properly is there any method to autoload Vite when I do php artisan serve
when Vite is loaded my code works correctly
scripts in package.json
"scripts": {
"dev": "vite",
"build": "vite build"
},
Cause of Problem:
In older versions of Laravel we were using laravel-mix package but now laravel js compiling engine is shifted to vite and it is much more faster.
In the case of mix engine whenever we run npm run dev generate compiled js code in public/js directory. and due to it we need to refresh page manually everytime.
But now In vite when you run npm run dev it just starts a vite server that continuously monitor your changes and reflect those changes on screen immediately. but it's not generate compiled js files in public/js directory
So, when your vite server not running it shows above error.
Solution:
If you want to run laravel without runing vite server by npm run dev you will need to run npm run build. It will generate compiled js files in public/js directory so then you will not have need to run vite server.
Caution: if you run npm run dev after the npm run build command your compiled templates will be removed. So, you will need to run npm run build once again after stopping vite server which is running using npm run dev
npm run dev
with vite is basically what
npm run watch
used to do back with mix.
If you focus on your back-end, try to run prod instead, so that your main page works while you deal with laravel.
Once you get to front-end work and need your js running, you need to have vite up during development. At any point you can stop the process, run a quick prod build and get back to whatever you want.
npm and artisan are two different tools that have nothing to do with each other. They need to run seperately.
You can extend your package.json to automatically start both with npm run serve:
{
...
"scripts": {
...
"serve": "php artisan serve & npm run dev"
},
...
}
It's because of your Node version. Check your Node Version
node -v
if it's below 16, you should upgrade it to the latest one then run
npm install && npm run dev

Npm run dev stuck at APP_URL

I created a new laravel project, installed breeze auth and ran npm install and npm run dev. But it's stuck at this screen for 15 minutes now. Nothing is moving on the terminal window.
All the commands I used was
laravel new shop
composer require laravel/breeze
php artisan breeze:install
npm install
npm run dev
Everything worked fine until npm run dev, but when I enter npm run dev command, I get this output and nothing else.
PS C:\shop> npm run dev
> dev
> vite
vite v2.9.13 dev server running at:
> Local: http://localhost:3000/
> Network: use `--host` to expose
ready in 364ms.
Laravel v9.19.0
> APP_URL: http://shop.test
Laravel version 9.19.0 replaced Mixer with Vite for more information check Bundling Assets (Vite)
if you want to work mixer install Laravel version /= 9.1.0
composer create-project Laravel/Laravel app_name 9.1.0
I used npm run build instead npm run dev. And that solved it, I guess.
I faced the same problem. I tried for many hours to solve this problem. Laravel 9.19.0+ is using Vite to replace Laravel Mix for bundling assets. https://laravel.com/docs/9.x/vite#main-content
Starter kit components like Laravel Breeze and Jetstream have been using #vite
#vite(['resources/css/app.css', 'resources/js/app.js'])
When we run npm run dev vite will create own host below.
> dev
> vite
vite v2.9.13 dev server running at:
> Local: http://localhost:3000/
> Network: use `--host` to expose
ready in 364ms.
Laravel v9.19.0
> APP_URL: http://shop.test
And alway embed our style and script with this host http://127.0.0.1:3000/
<link rel="stylesheet" href="http://127.0.0.1:3000/resources/css/app.css">
<script type="module" src="http://127.0.0.1:3000/resources/js/app.js"></script>
I found a file name hot in the folder public was been created during we run command npm run dev and it is never delete.
To work around I just delete hot file by add few code into package.json
From
"scripts": {
"dev": "vite",
"build": "vite build"
},
To
"scripts": {
"delhot": "npx rimraf public/hot",
"dev": "vite",
"build": "npm run delhot vite build"
},
I hope that next release version of Laravel Vite will fix this issue.
composer create-project Laravel/Laravel app_name 9.1.0
Just use this laravel ver

Vuejs installed or not?

I am a beginner in Vuejs.I want to develop an application with laravel and Vuejs.I have follow the step of installing laravel and Vuejs and execute this composer create-project --prefer-dist laravel/laravel demo "5.8.*" command.I verify to check that Vuejs is installed or not by adding the extension of Vuejs in google chrome and it showing Vuejs is installed.But when i execute the command vue --version in the putty by connecting server through SSH then it shows error that "vue command not found".Why?
May be this question is not proper to ask but i am very confusing that actually Vuejs is installed or not.And is the Vuejs files structure is same or different?
Thanks in advance.
Installing and compiling vue into a laravel project is different than using the vue cli.
In Laravel, Vue is included in the assets registry in the package.json file.
npm uses this file to pull in assets then allows you to build them. It pulls them in with npm install
Note: you need node.js installed on your system.
The build commands you can see at the top of the package.json. They usually are:
npm run dev, npm run prod, and npm run watch.
Here is the documentation on getting started with Laravel and Vue:
https://laravel.com/docs/7.x/frontend

I am using Putty to run and compile vue js + laravel app on Godaddy VPS. Changes are not taking effect

I am using Putty to run and compile vue js + laravel app on Godaddy VPS. Changes are not taking effect.
I have Laravel + Vue.js App on VPS.
When I make changes in code, I am running following command in Putty.
npm run dev
npm run watch
Changes are not being applied. Even when it shows all modules built successfully.
npm run watch should apply changes in code.
In local environment using wamp it works
oh, have you tried laravel cached views clear??
php artisan cache:clear

laravel mix not working and my localhost:8000 not work

I create a laravel project with vue js. At first I have created laravel new project and then command npm install. and then command npm run dev
When I command in windows powershell: npm run watch
then whole things are compiled and then When I change somehing in app.js in laravel project and save this file. There is no notice about laravel mix. Besides When I write in my web browser: localhost:8000
I can't see my project. I can see a error message: This site can’t be reached
How can I solve this problem.

Resources