2015-12-10 16:22:20 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var path = require('path');
|
|
|
|
var gulp = require('gulp');
|
|
|
|
var conf = require('./conf');
|
|
|
|
|
|
|
|
var browserSync = require('browser-sync');
|
|
|
|
var browserSyncSpa = require('browser-sync-spa');
|
|
|
|
|
|
|
|
var util = require('util');
|
|
|
|
|
|
|
|
var proxyMiddleware = require('http-proxy-middleware');
|
|
|
|
|
|
|
|
function browserSyncInit(baseDir, browser) {
|
|
|
|
browser = browser === undefined ? 'default' : browser;
|
|
|
|
|
|
|
|
var routes = null;
|
|
|
|
if(baseDir === conf.paths.src || (util.isArray(baseDir) && baseDir.indexOf(conf.paths.src) !== -1)) {
|
|
|
|
routes = {
|
|
|
|
'/bower_components': 'bower_components'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var server = {
|
|
|
|
baseDir: baseDir,
|
|
|
|
routes: routes
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* You can add a proxy to your backend by uncommenting the line below.
|
|
|
|
* You just have to configure a context which will we redirected and the target url.
|
|
|
|
* Example: $http.get('/users') requests will be automatically proxified.
|
|
|
|
*
|
2015-12-14 18:22:38 +00:00
|
|
|
* For more details and option, https://github.com/chimurai/http-proxy-middleware/blob/v0.9.0/README.md
|
2015-12-10 16:22:20 +00:00
|
|
|
*/
|
2015-12-14 18:22:38 +00:00
|
|
|
// server.middleware = proxyMiddleware('/users', {target: 'http://jsonplaceholder.typicode.com', changeOrigin: true});
|
2015-12-10 16:22:20 +00:00
|
|
|
|
|
|
|
browserSync.instance = browserSync.init({
|
|
|
|
startPath: '/',
|
|
|
|
server: server,
|
2015-12-22 16:20:05 +00:00
|
|
|
browser: browser,
|
|
|
|
ghostMode: false
|
2015-12-10 16:22:20 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
browserSync.use(browserSyncSpa({
|
|
|
|
selector: '[ng-app]'// Only needed for angular apps
|
|
|
|
}));
|
|
|
|
|
|
|
|
gulp.task('serve', ['watch'], function () {
|
|
|
|
browserSyncInit([path.join(conf.paths.tmp, '/serve'), conf.paths.src]);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('serve:dist', ['build'], function () {
|
|
|
|
browserSyncInit(conf.paths.dist);
|
|
|
|
});
|
2015-12-14 18:22:38 +00:00
|
|
|
|
|
|
|
gulp.task('serve:e2e', ['inject'], function () {
|
|
|
|
browserSyncInit([conf.paths.tmp + '/serve', conf.paths.src], []);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('serve:e2e-dist', ['build'], function () {
|
|
|
|
browserSyncInit(conf.paths.dist, []);
|
|
|
|
});
|