Laravel 项目更改后自动刷新 [英] Laravel project auto refresh after changes

查看:26
本文介绍了Laravel 项目更改后自动刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道是否有一种方法可以在 Laravel 项目中运行代码更改而无需每次都刷新页面.

Does anyone know if there is a way to run the code changes in a Laravel project without refreshing the page every time.

我知道要查看我需要的更改

I know that to see the changes I need to

php artisan serve

但我每次都这样做,这有点令人沮丧.

but I do it every time and it is kind of frustrating.

还是谢谢你.

推荐答案

你可以使用 Laravel Mix.

根据这部分的文档,您需要编辑您的webpack.mix.js 文件,并在最后添加:

According to this part of the documentation, you need to edit your webpack.mix.js file, and add this to the end:

mix.browserSync('127.0.0.1:8000');

它需要与 php artisan serve 命令的输出相匹配,您在其中找到了如下一行:

It needs to match to the output of the php artisan serve command, where you found a line something like this:

Laravel development server started: <http://127.0.0.1:8000>

此后,您必须同时运行 php artisan servenpm run watch 命令.在编辑文件时,您必须离开以运行这两个命令.

After this, you have to run the php artisan serve, and the npm run watch command simultaneously. You must leave to run both commands while you edit your files.

注意:第一次运行 npm run watch 时,它会安装其他组件.但是命令输出对此非常清楚.如果一切正常,Laravel Mix 会自动使用 http://localhost:3000 或类似内容打开你的浏览器.

Note: The first time you run the npm run watch, it installs additional components. But the command output is quite clear on that. If everything is in order, Laravel Mix automatically opens your browser with http://localhost:3000, or something like this.

这篇关于Laravel 项目更改后自动刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆