29

Using Laravel 5.4 and Mix, when I run npm run watch it compiles everything once and looks like it is waiting for changes, but when I make changes to any of my asset files it doesn't seem to detect anything. Is anyone else having this issue in 5.4 or have a solution?

Josh Mountain
  • 1,888
  • 10
  • 34
  • 51
  • Did you save your file? – Mahbub Jan 26 '17 at 05:43
  • @mrabbani Yes the files are saved, but watch doesn't pick them up. If I stop watch and run it again it will find the changes on the first compile but nothing after that. – Josh Mountain Jan 26 '17 at 17:58
  • 1
    I am facing the same issue. I run `npm run watch` and files are compiled only the first time. It seems that watch is waiting for changes but the only way to make it work is stop watch and run it again. Tried `node_modules/.bin/webpack --watch --watch-poll --config=node_modules/laravel-mix/setup/webpack.config.js` but still no luck. – KoKa Apr 19 '17 at 12:33

5 Answers5

40

The solution was provided by Jeffrey Way over at Laracasts.

Try adding the --watch-poll flag to your package.json script. Or just try:

node_modules/.bin/webpack --watch --watch-poll --config=node_modules/laravel-mix/setup/webpack.config.js

Josh Mountain
  • 1,888
  • 10
  • 34
  • 51
13

npm run watch-poll

It's working on ubuntu as well And auto compiling on code changes. Thank you.

Atiar Rahman
  • 194
  • 1
  • 9
5

npm run watch-poll

watch-poll periodically checks (polls) for changes e.g. every 1000ms it will manually check to see if any files have changed.

what laravel docs say?

You may find that in certain environments Webpack isn't updating when your files change. If this is the case on your system, consider using the watch-poll command. You can read up on the docs for a more information about mix.

Hussam Adil
  • 502
  • 7
  • 13
1

I prefer to use inotify-tools. To install this tool set run this command:

Ubuntu:

sudo apt install inotify-tools -y

Centos:

sudo yum -y install inotify-tools

then for big folders run:

sudo sysctl fs.inotify.max_user_watches=500000000

finally run this command to watch folder changes:

while true; do npm run dev; inotifywait -e modify,create,delete,move -r resources/ ; done

You can limit target watching directory (resources/ in this example) for better performance.

Mahoor13
  • 5,297
  • 5
  • 23
  • 24
0

I was using mix.scripts which doesn't actually compile your scripts, just copies them, so there is no npm readout on a compilation, because it's not compiling anything. If you aren't using mix.js or mix.sass (r any of the other compilers in your webpack.mix.js file then npm run watch will appear to do nothing because it is just copying in the background.

Abraham Brookes
  • 1,720
  • 1
  • 17
  • 32