gulp服务器
Today we'll be showing off a quick tip for making your Gulp files a little more useful.
今天,我们将展示使您的Gulp文件更有用的快速提示。
When building out Laravel applications, if we are using PHP's built-in server, then we can start our applications using:
在构建Laravel应用程序时,如果我们使用PHP的内置服务器,则可以使用以下命令启动应用程序:
$ php artisan serve
This will start our Laravel server and let us develop.
这将启动我们的Laravel服务器并让我们进行开发。
We must usually also start up Gulp (whether we use Elixir or plain Gulp).
通常,我们还必须启动Gulp(无论使用Elixir还是纯Gulp)。
使用Gulp启动PHP服务器 (Starting a PHP Server with Gulp)
Let's say we wanted to consolidate more commands into our Gulp file. There's just something cool about giving other users access to your project and giving them the following instructions:
假设我们想将更多命令整合到Gulp文件中。 给其他用户访问您的项目的权限,并给他们以下说明,这是一件很酷的事情:
- Clone/fork the repo 克隆/分叉仓库
- Install dependencies (
composer install
andnpm install
) 安装依赖项(composer install
和npm install
) - Start everything (
gulp
) 开始一切(大gulp
)
Simple and easy.
简单容易。
Luckily there's a neat npm package called gulp-connect-php.
幸运的是,有一个名为gulp-connect-php的整洁的npm软件包。
使用gulp-connect-php (Using gulp-connect-php)
Start a new Laravel install using the Laravel CLI tools.
使用Laravel CLI工具开始新的Laravel安装。
$ laravel new site
Now we can grab all the packages that we need:
现在,我们可以获取所需的所有软件包:
$ cd site
$ npm install gulp gulp-connect-php --save-dev
With these packages, let's move into our gulpfile.js
. Clear out what's in there currently (there will be some lines about elixir).
使用这些软件包,让我们进入gulpfile.js
。 清除当前存在的内容(关于长生不老药会有一些内容)。
任务 (The Task)
This is what our new gulpfile.js
will look like:
这就是我们新的gulpfile.js
样子:
// grab all our packages
var gulp = require('gulp'),
php = require('gulp-connect-php');
// create a task to serve the app
gulp.task('serve', function() {
// start the php server
// make sure we use the public directory since this is Laravel
php.server({
base: './public'
});
});
Now we can use this serve
task.
现在我们可以使用此serve
任务。
$ gulp serve
Note: If you run into any errors, make sure your Laravel installation is good to go. I had to create my .env
file and create a new application key using php artisan key:generate
to get this to work.
注意 :如果遇到任何错误,请确保您的Laravel安装良好。 我必须创建.env
文件,并使用php artisan key:generate
创建一个新的应用程序密钥,以使其正常工作。
结论 (Conclusion)
Just like that, with one simple package, we have given our gulpfile.js
another job to help simplify our development lives.
就像这样,通过一个简单的程序包,我们为gulpfile.js
提供了另一项工作,以帮助简化我们的开发工作。
翻译自: https://scotch.io/tutorials/use-gulp-to-start-a-laravel-php-server
gulp服务器