Laravel 项目更改后自动刷新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49392001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:32:25  来源:igfitidea点击:

Laravel project auto refresh after changes

laravelbrowser

提问by CarlosZ

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

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

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.

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

Thank you anyways.

还是谢谢你。

回答by senki

You can achieve this with Laravel Mix.

您可以使用Laravel Mix实现这一点

According to this partof the documentation, you need to edit your webpack.mix.jsfile, and add this to the end:

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

mix.browserSync('127.0.0.1:8000');

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

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

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

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

在此之后,您必须同时运行php artisan serve, 和npm run watch命令。在编辑文件时,您必须离开以运行这两个命令。

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.

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

回答by Faisal khokher

add in webpack.max.js file in laravel

在 laravel 中添加 webpack.max.js 文件

mix.browserSync('127.0.0.1:8000');

then run this command

然后运行这个命令

> npm install browser-sync [email protected] --save-dev --production=false

after this run npm run watch

在运行 npm run watch 之后

> Browsersync automatic run your port 3000