From e293274021bbd64579eaa3fb2c814a39ea275d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Fox?= Date: Tue, 12 Apr 2016 23:30:31 -0300 Subject: [PATCH] Add Browsersync options to scripts task --- generators/app/templates/gulp/_scripts.js | 8 +++++++- generators/app/templates/gulp/_watch.js | 2 ++ test/template/test-scripts.js | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/generators/app/templates/gulp/_scripts.js b/generators/app/templates/gulp/_scripts.js index 48be0ead..1d4c984d 100644 --- a/generators/app/templates/gulp/_scripts.js +++ b/generators/app/templates/gulp/_scripts.js @@ -14,8 +14,14 @@ var $ = require('gulp-load-plugins')(); <% if (props.jsPreprocessor.srcExtension !== 'es6' && props.jsPreprocessor.key !== 'typescript') { -%> gulp.task('scripts-reload', function() { + var bsOptions = {once: true}; +<% if (props.jsPreprocessor.key === 'noJsPrepro') { -%> + if (conf._gulpWatchEvent) { + bsOptions.match = conf._gulpWatchEvent.path; + } +<% } -%> return buildScripts() - .pipe(browserSync.stream()); + .pipe(browserSync.stream(bsOptions)); }); gulp.task('scripts', function() { diff --git a/generators/app/templates/gulp/_watch.js b/generators/app/templates/gulp/_watch.js index 22578f62..cfc0c9d9 100644 --- a/generators/app/templates/gulp/_watch.js +++ b/generators/app/templates/gulp/_watch.js @@ -42,11 +42,13 @@ gulp.task('watch', [<%- watchTaskDeps.join(', ') %>], function () { path.join(conf.paths.src, '/app/**/*.<%- props.jsPreprocessor.extension %>') ], function(event) { <% } -%> + conf._gulpWatchEvent = event; if(isOnlyChange(event)) { gulp.start('scripts-reload'); } else { gulp.start('inject-reload'); } + delete conf._gulpWatchEvent; }); <% } -%> diff --git a/test/template/test-scripts.js b/test/template/test-scripts.js index 3e7513bf..66d48d23 100644 --- a/test/template/test-scripts.js +++ b/test/template/test-scripts.js @@ -74,4 +74,16 @@ describe('gulp-angular scripts template', function () { result.should.not.match(/typescript/); }); + it('should add match to browserSync options when not using a js preprocessor', function () { + model.props.jsPreprocessor.key = 'noJsPrepro'; + var result = scripts(model); + result.should.match(/bsOptions\.match/); + }); + + it('should not add match to browserSync options when using a js preprocessor', function () { + model.props.jsPreprocessor.key = 'babel'; + var result = scripts(model); + result.should.not.match(/bsOptions\.match/); + }); + });