lemur/gulp/server.js

69 lines
1.9 KiB
JavaScript
Raw Normal View History

2015-06-22 22:47:27 +02:00
'use strict';
var gulp = require('gulp');
var browserSync = require('browser-sync');
2018-08-22 22:21:35 +02:00
var httpProxy = require('http-proxy');
2015-06-22 22:47:27 +02:00
/* This configuration allow you to configure browser sync to proxy your backend */
2019-05-01 01:21:54 +02:00
var proxyTarget = 'http://localhost:8000/'; // The location of your backend
var proxyApiPrefix = '/api/'; // The element in the URL which differentiate between API request and static file request
2015-06-22 22:47:27 +02:00
var proxy = httpProxy.createProxyServer({
2019-05-01 01:21:54 +02:00
target: proxyTarget
2015-06-22 22:47:27 +02:00
});
function proxyMiddleware(req, res, next) {
2019-05-01 01:21:54 +02:00
if (req.url.indexOf(proxyApiPrefix) !== -1) {
proxy.web(req, res);
} else {
next();
}
2015-06-22 22:47:27 +02:00
}
function browserSyncInit(baseDir, files, browser) {
browser = browser === undefined ? 'default' : browser;
browserSync.instance = browserSync.init(files, {
startPath: '/index.html',
2019-05-01 01:21:54 +02:00
server: {
middleware: [proxyMiddleware],
baseDir: baseDir,
routes: {
'/bower_components': './bower_components'
}
2015-06-22 22:47:27 +02:00
},
browser: browser,
ghostMode: false
});
}
gulp.task('watch', gulp.series(['dev:styles', 'dev:scripts', 'dev:inject', 'dev:fonts'], function (done) {
2020-12-09 04:20:28 +01:00
gulp.watch('app/styles/**/*.less', gulp.parallel('dev:styles'));
gulp.watch('app/styles/**/*.css', gulp.parallel('dev:styles'));
gulp.watch('app/**/*.js', gulp.parallel('dev:scripts'));
gulp.watch('app/images/**/*', gulp.parallel('build:images'));
gulp.watch('bower.json', gulp.parallel('dev:inject'));
done();
}));
gulp.task('serve', gulp.series('watch', function () {
2015-06-22 22:47:27 +02:00
browserSyncInit([
'.tmp',
'lemur/static/app'
2015-06-22 22:47:27 +02:00
], [
'.tmp/*.html',
'.tmp/styles/**/*.css',
'lemur/static/app/angular/**/*.js',
'lemur/static/app/partials/**/*.html',
'lemur/static/app/images/**/*',
'lemur/static/app/angular/**/*',
'lemur/static/app/index.html'
]);
2020-12-09 04:20:28 +01:00
}));
2015-06-22 22:47:27 +02:00
2020-12-09 04:20:28 +01:00
gulp.task('serve:dist', gulp.series('build', function () {
2015-06-22 22:47:27 +02:00
browserSyncInit('lemur/static/dist');
2020-12-09 04:20:28 +01:00
}));