简体   繁体   中英

`npm run watch` not working in Laravel 5.4

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?

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

npm run watch-poll

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

npm run watch-poll

watch-poll periodically checks (polls) for changes eg 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 .

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM