How to run only one webpack process in Laravel Application? - php

is there any utility to pass through npm run dev variable that may compile only one process
for example
npm run dev --sass or npm run dev --js --styles --scripts
thank you in advance

No, there is no such function available by default. The only thing (that might help you) you can do is running npm run watch, which only compiles changed files again.

Related

How to fix Vite manifest not found at: /app/public/build/manifest.json?

It works locally just fine, but as I deploy it to a host, this popped up, not sure what to look or what to do.
Any suggestions? thanks
I would suggest running npm install && npm run dev as this seems like a default laravel app.
This would generate the correct files for local development.
If you want to run this in production you should run npm run prod somewhere in your build pipeline.
In my case, the
npm run build
command did the work.

How to run/develop laravel + vue.js (laravue) app properly

before i start, i need to say that i'm aware that this question is a beginner's one.
I've found this dashboard combination of Laravel and Vue.js that i wanted to play with, to then start developing a real web application. laravue
There's just a single question that is confusing me: while testing it on xampp with the commands "npm run watch" and "php artisan serve" i see myself obliged to npm run the project, every time i make a file change.
So what is the right way to check all the changes i make? By just refreshing the browser window.
Thank you for all the responses.
I've solved the problem by running "npm run watch" and "php artisan serve" on two separated command-line windows.
Was totally unaware of that and it's part of the learning curve.
Thank you, this is now solved.
npm run watch automatically builds your assets and then watch any save on the concerned files. Whenever a save happens, npm run watch rebuilds everything, but you won't be aware on your web browser except by refreshing.
P.S: Sometimes npm run watch does not work well, then use npm run watch-poll instead
https://laravel.com/docs/7.x/mix#running-mix
npm run watch or npm run watch-poll will automatically rebuild your assets but don't apply to the browser without manual refresh. Meaning you have to reload browser after compiling done.
Hot Module Replacement(HMR - or Hot Reloading) works same as npm run watch and apply changes to browser automatically, so you don't have to reload browser to see the changes.
Following this document, HRM works well with the fresh installation (latest code on master) as my test.
npm run hot result:
➜ npm run hot
> laravue#0.11.0 hot [src]
> cross-env NODE_ENV=development BABEL_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js
ℹ 「wds」: Project is running at http://localhost:8080/
ℹ 「wds」: webpack output is served from http://localhost:8080/
ℹ 「wds」: Content not from webpack is served from [src]/public
ℹ 「wds」: 404s will fallback to /index.html
php artisan serve result:
➜ php artisan serve
Laravel development server started: http://127.0.0.1:8000
And browser:

How to run and watch local server at the same time?

I've been having some issues setting up my local server. I can get it to run with php artisan serve, but I can't add npm run watch at the same time.
I've done npm install and updated my node too. It says to run php artisan serve first and then to run npm run watch, but once I've done the artisan serve, it doesn't let me type in anything else.
If I run npm run watch before php artisan serve, it opens up the wrong port (3000 instead of 8000), too.
Can someone please let me know what is going on? Have you encountered this before? Nothing I could find on here matched my problem, but in case I missed it, please let me know. And if you need any further information, as in logs, etc.
Open a new terminal tab and run npm run watch on that one. If you are using default Windows cmd take a loot at cmder or the new Windows Terminal.

Make Capistrano use alias on sever when running scripts

I have the following problem using Capistrano with laravel:
My hosting provider does not provide a cli php version via php but only via a usr/bin/local/.../PHP-CLI command
I did create an alias for it in my .bash_profile so running composer install from the cli is no problem.
However, Capistrano (as far as I understand due to it starting in a very basic shell http://capistranorb.com/documentation/faq/why-does-something-work-in-my-ssh-session-but-not-in-capistrano/) does not load this alias, so I get an error from the composer scripts e.g. php artisan.
However, on my dev machine I need to keep it as php, since this is where php is here.
How can I solve this problem best? Any more info you need? Thanks.
Just in case it helps, this is how I call the script:
desc 'Composer install'
task :composer_install do
on roles(:app), in: :groups, limit:1 do
execute "/usr/local/bin/php5-56STABLE-CLI composer.phar install --working-dir #{fetch(:release_path)}"
execute "cp #{fetch(:deploy_to)}/shared/.env #{fetch(:release_path)}/.env"
end
end
It sounds like your scenario is the perfect fit for Capistrano's "command map" feature, as documented here: https://github.com/capistrano/sshkit#the-command-map.
Here are the two main takeaways:
Write your Capistrano execute commands so that the binary name (php) is a separate argument. This will allow it to be substituted using the command map. For example:
execute :php, "composer.phar install --working-dir #{fetch(:release_path)}"
In your Capistrano deployment config, tell the command map how to substitute the :php command, like this:
SSHKit.config.command_map[:php] = "/usr/local/bin/php5-56STABLE-CLI"
If you want this substitution to affect all deployment environments, place it in deploy.rb. If it only applies to your production environment, then put it in production.rb.
Okay, my current workaround is the following:
in your capistrano deploy.rb in the script that you execute at deploy update.
desc 'Composer install'
task :composer_install do
on roles(:app), in: :groups, limit:1 do
execute "/usr/local/bin/php5-56STABLE-CLI /path/to/composer.phar install --working-dir #{fetch(:release_path)} --no-scripts"
execute "cd #{fetch(:release_path)} && /usr/local/bin/php5-56STABLE-CLI artisan clear-compiled"
execute "cd #{fetch(:release_path)} && /usr/local/bin/php5-56STABLE-CLI artisan optimize"
end
end
end
after "deploy:updated", "deploy:composer_install"
I am not 100% sure if the artisan clear-compiled is needed. Anyway, those 2 are composer scripts that would normally be called via composer, but the --no-scripts flag keeps them from being called, so that it does not fail on install. When calling them from capistrano, I can easily change which php to use, as you can see.
However if anyone has a better solution, please let me know.

Run PHPUnit tests on change

I'd like to run my PHPUnit tests (or at least a subset of them) whenever a file changes on disk. Very similar to what you can do with "grunt watch". I have a project in which I have both JS and PHP, and am using Grunt. There I shell out to PHPUnit to have it run on top of my JS tests using grunt watch. While that works just fine, it seems like an awful lot of hassle to do this in a PHP only project. I'd need to introduce grunt, and add a dependency on node. Plus I have a lot of such PHP projects. A more simple solution is thus in order.
You can use node watch which is quite sweet:
Run npm init to set up a package (takes a minute), then
npm install --save-dev watch
Then edit your package.json file to include these two entries:
"scripts": {
"test": "bin/phpunit tests --color",
"test:watch": "watch 'npm run --silent test' ."
},
Then trigger the watching with:
npm run test:watch
(credit due to this interesting article)
I've wrote a blog post on this a while back: http://edorian.github.io/2010-03-11-running-your-unit-tests-everytime-you-save-a-file/
The most basic command would be:
pywatch phpunit .
which would mean "monitor all files in this directory and below for changes and if one of them changes run PHPUnit".
If you have a lot of files in there (assets etc) that can get slow so a better/faster version is:
find -name '*.php' | xargs pywatch "./runSuite.sh"
which only monitors changes to .php files
Maybe you can try phpunit-watcher. https://packagist.org/packages/spatie/phpunit-watcher
First, to install phpunit-watcher with composer require spatie/phpunit-watcher --dev, and then, modify the composer.json to add an item in scripts property:
{
"scripts" : {
"test" : "./vendor/bin/phpunit-watcher watch --bootstrap vendor/autoload.php tests/"
}
}
Then, you can run test cases with: composer test.
Sometimes, you should run composer run test --timeout=0, otherwise the process would be killed after 300 seconds.
In PHPStorm you can configure File Watcher that will execute shell commands for you at file modifications. For example you can have one File Watcher that will trigger on php file modification and will run phpunit command with all necessary commands.
More info about File Watchers can be found on JetBrains web help page: https://www.jetbrains.com/phpstorm/webhelp/using-file-watchers.html
A dead simple way to do this, using inotifywait and a bash script:
#!/bin/bash
while true; do
FILE=$(inotifywait --exclude=".*.*sw*" --exclude="4913" ./ --format "%w%f" -e close_write) &&
clear &&
phpunit --color $FILE
done
Then you just run that in a terminal (or however you want) and you're good. I'm running tmux, so I just have a stacked pane set up, with a little window to see my test results. Just run this script in the directory where your tests live.
Works well for me.
Also, this script is Vim friendly (Vim creates a file, 4913, during saves, this script ignores it).
It was totally inspired from various places around the web -- probably even from some of these answers.
Install grunt and use https://github.com/SaschaGalley/grunt-phpunit
Then you'd setup the phpunit task under with the watch task. This is how I do it right now.
I've created a solution to deal with this very problem: "What's Changed?" In short, there are cases where you have some really large test suites and you only want to run the tests relevant to the classes which have changed.
You can pull this in via composer by running composer require --dev icyapril/whats-changed
With this in place just run ./vendor/bin/whatschanged and only the file changed in your last commit or in your working directory will be run. Magic!
You can use inotifywait, see https://speakerdeck.com/rowan_m/building-better-developers-2?slide=31 for a PHPUnit example.
I found the phpunit-testrunner node package, which is of use for my problem. One config json file per PHP project, which can then be used by anyone that has the node package installed. Also cross platform. Still requires node though, so not an ideal solution.
i found this solution use node+gulp
0. install node
1. npm init
2. npm install gulp --save-dev
create a gulpfile.js and put this
var gulp = require('gulp'),
util = require('util'),
exec = require('child_process').exec;
gulp.task('phpunit', function() {
exec('phpunit -c my_project_name/App', function(error, stdout) {
util.puts(stdout);
});
});
gulp.task('default',['phpunit'], function() {
gulp.watch('my_project_name/**/*.php', ['phpunit']);
});
my_project_name/App is the path of all source code
if add extension add this line on default task
gulp.watch('my_project_name//*.otherext', ['phpunit']);
after edit php file run the phpunit test

Categories