Created
January 28, 2016 03:37
-
-
Save kevinweaver/64823ca10a39aa5e7924 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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'); | |
var exec = require('child_process').exec; | |
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, | |
middleware: [ | |
proxyMiddleware('/api', { target: 'http://localhost:3000' }) | |
] | |
}; | |
/* | |
* 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. | |
* | |
* For more details and option, https://github.com/chimurai/http-proxy-middleware/blob/v0.9.0/README.md | |
*/ | |
// server.middleware = proxyMiddleware('/users', {target: 'http://jsonplaceholder.typicode.com', changeOrigin: true}); | |
browserSync.instance = browserSync.init({ | |
port: 9000, | |
startPath: '/', | |
server: server, | |
browser: browser | |
}); | |
} | |
browserSync.use(browserSyncSpa({ | |
selector: '[ng-app]'// Only needed for angular apps | |
})); | |
gulp.task('rails', function() { | |
exec("rails server"); | |
}); | |
gulp.task('serve', ['watch'], function () { | |
browserSyncInit([path.join(conf.paths.tmp, '/serve'), conf.paths.src]); | |
}); | |
gulp.task('serve:fullstack', ['rails', 'serve']); | |
gulp.task('serve:dist', ['build'], function () { | |
browserSyncInit(conf.paths.dist); | |
}); | |
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, []); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
works perfectly. thanks