简体   繁体   English

将Grunt / Gulp和Livereload集成到服务于PHP / Zend的现有Apache服务器

[英]Integrating Grunt/Gulp and Livereload to existing Apache server serving PHP/Zend

I'm working on a PHP project using the Zend framework which is being served locally using Apache. 我正在使用Zend框架开发一个PHP项目,该框架使用Apache在本地提供。 Is there a plug-in/configuration for Grunt/Gulp that will allow me to use this existing server and reload my browser whenever changes are made to my phtml/php, CSS, and JavaScript files? 是否有Grunt / Gulp的插件/配置允许我使用这个现有服务器并在我的phtml / php,CSS和JavaScript文件发生变化时重新加载我的浏览器?

The normal live-reload plugins will work just fine. 正常的live-reload插件可以正常工作。 It works by running a separate server that simply reports changes — it doesn't serve your code directly. 它的工作原理是运行一个仅报告更改的单独服务器 - 它不直接为您的代码提供服务。

If you are using gulp, you follow the directions in the gulp-livereload README for setting up and running the LR server. 如果您正在使用gulp,请按照gulp-livereload README中的说明设置和运行LR服务器。 The plugin will notify the LR server that a file has changed, and the LR server will notify your browser that the change has occurred. 该插件将通知LR服务器文件已更改,LR服务器将通知您的浏览器已发生更改。

You can easily add watches onto any file served up to the browser, and notify the LR server of them — even if they aren't processed by gulp (or grunt) otherwise. 您可以轻松地将监视添加到提供给浏览器的任何文件上,并通知LR服务器 - 即使它们没有被gulp(或grunt)处理。

You have three choices for triggering the change notification within the browser. 在浏览器中触发更改通知有三种选择。

  1. If you have separate development and production builds (and I would hope you do), then use the gulp-embedlr plugin to inject a script tag into your HTML or PHP file. 如果您有单独的开发和生产版本(我希望您这样做),那么使用gulp-embedlr插件将脚本标记注入HTML或PHP文件。

  2. If you can't get that to work with your PHP setup, then you could inject the script tag yourself using PHP, such that it's only injected when running in dev mode. 如果您无法使用PHP设置,那么您可以使用PHP自己注入脚本标记,这样只有在开发模式下运行时才会注入脚本标记。 The code can be gotten from the embedlr plugin, but it looks something like this: 代码可以从embedlr插件获得,但它看起来像这样:

     <script type="text/javascript">document.write('<script src="//localhost:35729/livereload.js?snipver=1" type="text/javascript"><\\/script>')</script> 

    Obvisouly, you can tweak the source domain and port to match your LR setup if necessary. 显然,如果需要,您可以调整源域和端口以匹配您的LR设置。

  3. If you cannot do this, don't have a way to run separate dev and production environments, or just don't want to have this handled in an automatic manner that works across all browsers (including mobile), you can install the LiveReload browser plugin. 如果你不能这样做,没有办法运行单独的开发和生产环境,或者只是不希望以自动方式处理所有浏览器(包括移动设备),你可以安装LiveReload浏览器插入。 Just look for it on your browser's plugin/add-on store/marketplace/whatever. 只需在浏览器的插件/附加商店/市场/其他内容中查找它。 This requires you to remember to turn it on everytime you are doing development work. 这要求您记住每次进行开发工作时都要打开它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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