Server in gulp and grunt

0

I've been researching but I believe I'm not asking the right questions. I want to use gulp instead of grunt but how do I run a "grunt server" using gulp? Why the gulp watch has nothing to do with using a certain access door?

My problem with grunt is setup. It's impossible to make it work I've given up. Gulp runs cool but I can not find that command. Actually, I do not even know if he exists. Can anyone get me that doubt?

    
asked by anonymous 02.08.2015 / 16:05

1 answer

1

Yes, the watch gulp method tells it to watch changes occurring in the past files or directories so that it executes a certain task when it exists.

The grunt server command actually runs a task named server that is available through some plugin, usually grunt-contrib-connect that is used for this purpose.

A plugin equivalent to it in gulp would be gulp-connect . To use it you need to have the gulp CLI installed globally and also installed locally in your project directory as well as the plugin.

To do this run the command inside the folder of your project (after installing gulp globally):

npm install --save-dev gulp gulp-connect

Then just create the file gulpfile.js . I'll assume you already have your package.json file created if you do not use the npm init command and follow the instructions passed by it to do it.

In your gulpefile.js file just call the plugin using require of nodejs and create the task responsible for starting the server by following the plugin documentation:

var gulp    = require('gulp'), // Faz a chamada do gulp
connect = require('gulp-connect'); // Faz a chamada do plugin gulp-connect responsável por iniciar o servidor

gulp.task('server', function() {  // Criamos uma tarefa chamada 'server' responsável por iniciar o servidor na porta 8888
  connect.server({
    port: 8888 // A porta onde o servidor estará disponível 
  });
});

gulp.task('default', ['server']); // Aqui temos a terefa padrão que é executada ao rodar o comando gulp no terminal

Then just run the gulp command on the terminal inside the directory of your project and it will execute the tasks, in this case the start of the server.

In my example folder I created a file index.html with a simple message to really know if the server is working or not, and as expected you can see it working in the following image:

You can read the plugin's documentation for more details and other functions it can perform such as LiveReload.

    
02.08.2015 / 19:19