Advertisement
Gordon___From

Untitled

Oct 20th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. var path = require('path');
  4. var gulp = require('gulp');
  5. var conf = require('./conf');
  6.  
  7. var browserSync = require('browser-sync');
  8. var browserSyncSpa = require('browser-sync-spa');
  9.  
  10. var util = require('util');
  11.  
  12. var proxyMiddleware = require('http-proxy-middleware');
  13.  
  14. function browserSyncInit(baseDir, browser) {
  15.   browser = browser === undefined ? 'default' : browser;
  16.  
  17.   var routes = null;
  18.   if(baseDir === conf.paths.src || (util.isArray(baseDir) && baseDir.indexOf(conf.paths.src) !== -1)) {
  19.     routes = {
  20.       '/bower_components': 'bower_components'
  21.     };
  22.   }
  23.  
  24.   var server = {
  25.     baseDir: baseDir,
  26.     routes: routes
  27.   };
  28.  
  29.   /*
  30.    * You can add a proxy to your backend by uncommenting the line below.
  31.    * You just have to configure a context which will we redirected and the target url.
  32.    * Example: $http.get('/users') requests will be automatically proxified.
  33.    *
  34.    * For more details and option, https://github.com/chimurai/http-proxy-middleware/blob/v0.9.0/README.md
  35.    */
  36.   // server.middleware = proxyMiddleware('/users', {target: 'http://jsonplaceholder.typicode.com', changeOrigin: true});
  37.  
  38.   browserSync.instance = browserSync.init({
  39.     startPath: '/',
  40.     server: server,
  41.     browser: browser
  42.   });
  43. }
  44.  
  45. browserSync.use(browserSyncSpa({
  46.   selector: '[ng-app]'// Only needed for angular apps
  47. }));
  48.  
  49. gulp.task('serve', ['watch'], function () {
  50.   browserSyncInit([path.join(conf.paths.tmp, '/serve'), conf.paths.src]);
  51. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement