Skip to content

Commit 1aaec10

Browse files
author
Sebastian Henneberg
committed
replaced gulp-connect with browsersync, closes #25
1 parent eaf1a3a commit 1aaec10

9 files changed

+36
-52
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Boilerplate gulp tasks for quick project setup.
99
var gulp = require('gulp');
1010
var modular = require('gulp-modular');
1111

12-
var tasks = ['bower', 'clean', 'sass', 'configScripts', 'connect', 'fonts', ...];
12+
var tasks = ['bower', 'clean', 'sass', 'configScripts', 'browserSync', 'fonts', ...];
1313
var config = {...};
1414

1515
modular(gulp, tasks, config);
@@ -44,7 +44,7 @@ Detailed documentation of our best practice workflow and the config object will
4444
- `bowerScripts` concats all scripts from the bower dependencies and stores the file to a particular distribution folder.
4545

4646
## Local Server
47-
- `connect` provides a small HTTP server for local testing. It serves the requested file if available, the `index.html` otherwise (to support Angular HTML5 mode)
47+
- `browserSync` provides a small HTTP server for local testing. It serves the requested file if available, the `index.html` otherwise (to support Angular HTML5 mode)
4848
- `open` opens up the default web browser after the local HTTP server has started.
4949
- `reload` is responsible to reload the current page in the web browser whenever distribution files have changed.
5050
- `watch` checks files for changes and triggers the reload (see above).

index.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

33

4+
var browserSync = require('browser-sync').create();
5+
46
module.exports = function(gulp, tasks, config) {
57

68
if (tasks.indexOf('bower') !== -1) {
@@ -19,8 +21,8 @@ module.exports = function(gulp, tasks, config) {
1921
require('./tasks/configScripts')(gulp, config.env.constants, config.configName, config.dist.js, config.env.rev);
2022
}
2123

22-
if (tasks.indexOf('connect') !== -1) {
23-
require('./tasks/connect')(gulp, config.bases.dist, config.port);
24+
if (tasks.indexOf('browserSync') !== -1) {
25+
require('./tasks/browserSync')(gulp, browserSync, config.bases.dist, config.port);
2426
}
2527

2628
if (tasks.indexOf('fonts') !== -1) {
@@ -64,15 +66,11 @@ module.exports = function(gulp, tasks, config) {
6466
}
6567

6668
if (tasks.indexOf('protractor') !== -1) {
67-
require('./tasks/protractor')(gulp, config.bases.dist);
68-
}
69-
70-
if (tasks.indexOf('reload') !== -1) {
71-
require('./tasks/reload')(gulp, config.bases.dist);
69+
require('./tasks/protractor')(gulp, browserSync, config.bases.dist);
7270
}
7371

7472
if (tasks.indexOf('sass') !== -1) {
75-
require('./tasks/sass')(gulp, tasks, config.app.scss, config.dist.css, config.env.rev, config.dist.fonts, config.sourceMapsPath);
73+
require('./tasks/sass')(gulp, tasks, browserSync, config.app.scss, config.dist.css, config.env.rev, config.dist.fonts, config.sourceMapsPath);
7674
}
7775

7876
if (tasks.indexOf('scripts') !== -1) {
@@ -96,7 +94,7 @@ module.exports = function(gulp, tasks, config) {
9694
}
9795

9896
if (tasks.indexOf('watch') !== -1) {
99-
require('./tasks/watch')(gulp, tasks, config);
97+
require('./tasks/watch')(gulp, tasks, browserSync, config);
10098
}
10199

102100
};

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"homepage": "https://github.com/ONE-LOGIC/gulp-modular",
2929
"dependencies": {
30+
"browser-sync": "^2.9.1",
3031
"connect-history-api-fallback": "^1.1.0",
3132
"del": "^1.2.0",
3233
"extend": "^2.0.1",
@@ -37,7 +38,6 @@
3738
"gulp-cached": "^1.1.0",
3839
"gulp-compass": "^2.1.0",
3940
"gulp-concat": "^2.5.2",
40-
"gulp-connect": "^2.2.0",
4141
"gulp-debug": "^2.0.1",
4242
"gulp-exit": "0.0.2",
4343
"gulp-flatten": "0.0.4",
@@ -46,7 +46,6 @@
4646
"gulp-imagemin": "^2.3.0",
4747
"gulp-inject": "^1.3.1",
4848
"gulp-jshint": "^1.11.0",
49-
"gulp-livereload": "^3.8.0",
5049
"gulp-maven-deploy": "^0.2.0",
5150
"gulp-minify-css": "^1.1.6",
5251
"gulp-minify-html": "^1.0.3",

tasks/browserSync.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
var history = require('connect-history-api-fallback');
4+
5+
module.exports = function(gulp, browserSync, root, port) {
6+
gulp.task('browserSync', ['build'], function() {
7+
browserSync.init({
8+
server: {
9+
baseDir: root
10+
},
11+
port: port,
12+
middleware: [history()]
13+
});
14+
});
15+
};

tasks/connect.js

-18
This file was deleted.

tasks/protractor.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
'use strict';
22

3-
var connect = require('gulp-connect'),
4-
protractor = require('gulp-protractor').protractor,
3+
var protractor = require('gulp-protractor').protractor,
54
exit = require('gulp-exit');
65

76

8-
module.exports = function(gulp, src) {
7+
module.exports = function(gulp, browserSync, src) {
98
gulp.task('protractor', function(done) {
109
gulp.src(['e2e/**/*.js'])
1110
.pipe(protractor({
@@ -16,9 +15,9 @@ module.exports = function(gulp, src) {
1615
}).on('end', done);
1716
});
1817

19-
gulp.task('e2e:singleRun', ['connect', 'protractor'], function() {
18+
gulp.task('e2e:singleRun', ['browserSync', 'protractor'], function() {
2019
gulp.src(src)
21-
.pipe(connect.serverClose());
20+
.pipe(browserSync.exit());
2221
gulp.src(src)
2322
.pipe(exit());
2423
});

tasks/reload.js

-12
This file was deleted.

tasks/sass.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var sass = require('gulp-sass'),
24
sourceMaps = require('gulp-sourcemaps'),
35
autoPrefixer = require('gulp-autoprefixer'),
@@ -7,7 +9,7 @@ var sass = require('gulp-sass'),
79
_ = require('underscore');
810

911

10-
module.exports = function(gulp, tasks, src, dest, revFlag, manifestPath, sourceMapsPath) {
12+
module.exports = function(gulp, tasks, browserSync, src, dest, revFlag, manifestPath, sourceMapsPath) {
1113
var mergedTasks = _.intersection(tasks, ['fonts']);
1214
gulp.task('styles', mergedTasks, function (done) {
1315
var optionsSass = {
@@ -30,7 +32,8 @@ module.exports = function(gulp, tasks, src, dest, revFlag, manifestPath, sourceM
3032
.pipe(gulpif(revFlag, revReplace(optionsRev)))
3133
.pipe(gulpif(revFlag, rev()))
3234
.pipe(sourceMaps.write(sourceMapsPath))
33-
.pipe(gulp.dest(dest));
35+
.pipe(gulp.dest(dest))
36+
.pipe(browserSync.stream({match: '**/*.css'}));
3437
done();
3538
});
3639
};

tasks/watch.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var liveReload = require('gulp-livereload');
44

5-
module.exports = function(gulp, tasks, config) {
5+
module.exports = function(gulp, tasks, browserSync, config) {
66
gulp.task('watch', ['build'], function() {
77
liveReload.listen();
88
gulp.watch(config.app.index, ['justIndex']);
@@ -23,6 +23,6 @@ module.exports = function(gulp, tasks, config) {
2323
gulp.watch(config.app.js, ['scripts']);
2424
gulp.watch(config.bowerjson, ['bowerScripts', 'bowerStyles', 'bowerFonts']);
2525
// watch any change in dist folder; reload immediately in case of detected change
26-
gulp.watch(config.bases.dist + '**', ['reload']);
26+
gulp.watch([config.bases.dist + '**', '!**/*.css', '!**/*.css.map'], browserSync.reload);
2727
});
2828
};

0 commit comments

Comments
 (0)