gulp服务器_使用Gulp启动Laravel PHP服务器

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服务器并让我们进行开发。

laravel-artisan-serve

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文件中。 给其他用户访问您的项目的权限,并给他们以下说明,这是一件很酷的事情:

  1. Clone/fork the repo

    克隆/分叉仓库
  2. Install dependencies (composer install and npm install)

    安装依赖项( composer installnpm install
  3. 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

laravel-new-command

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

laravel-gulp-connect-php-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服务器

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值