Vitalij
Vitalij

Reputation: 4625

How to run `ionic serve` from Gulp script

I am trying to setup end to end tests using protractor and gulp. So in order to execute my tests on the CI server I will need spin off a server which serves ionic my html/js/css.

I am not entirely sure how ionic cli triggers the server, does it have some sort of task runner under the hood? If so, could I trigger it from the gulp script?

Upvotes: 3

Views: 2189

Answers (2)

AdityaParab
AdityaParab

Reputation: 7100

This is not the most elegant way but I believe this gets the job done.

First include child-process in your gulpfile.js

var exec = require('child_process').exec;

Create a new gulp task startServer like

gulp.task('startServer', function(){
    exec('ionic serve', function (err, stdout, stderr) {});
});

Pass this new task to your default task like,

gulp.task('default', [/*'task1','task2',...,*/'startServer']);

Then simply run gulp instead of ionic serve and you're all set.

Hope that helps. :)

Upvotes: 1

Nikola
Nikola

Reputation: 15038

As you can read here: http://www.reddit.com/r/ionic/comments/362log/how_does_ionic_serve_all_work/, it starts its own web server (like when using WAMPP or XAMPP for example).

So, I actually went to test this and it indeed is true; if you're familiar with XAMPP or WAMPP, you can start your ionic project inside the www folder of WAMPP and then you'll be able to access it via http://localhost/myapp/www link (without using ionic serve command), if you've started your ionic app with ionic start myapp.

I'm not that experienced with Gulp, but you may look if this plugin https://www.npmjs.com/package/gulp-live-server would help you achieve your task.

Upvotes: 0

Related Questions