Skip to content

Commit 8683802

Browse files
committed
feat(Gruntfile): switch to BrowserSync yeoman#1029
1 parent b0910b4 commit 8683802

File tree

3 files changed

+207
-48
lines changed

3 files changed

+207
-48
lines changed

1029.diff

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
diff --git a/templates/common/root/_Gruntfile.js b/templates/common/root/_Gruntfile.js
2+
index a715598..f966742 100644
3+
--- a/templates/common/root/_Gruntfile.js
4+
+++ b/templates/common/root/_Gruntfile.js
5+
@@ -43,10 +43,7 @@ module.exports = function (grunt) {
6+
},<% } else { %>
7+
js: {
8+
files: ['<%%= yeoman.app %>/scripts/{,*/}*.js'],
9+
- tasks: ['newer:jshint:all'],
10+
- options: {
11+
- livereload: '<%%= connect.options.livereload %>'
12+
- }
13+
+ tasks: ['newer:jshint:all']
14+
},
15+
jsTest: {
16+
files: ['test/spec/{,*/}*.js'],
17+
@@ -64,9 +61,6 @@ module.exports = function (grunt) {
18+
files: ['Gruntfile.js']
19+
},
20+
livereload: {
21+
- options: {
22+
- livereload: '<%%= connect.options.livereload %>'
23+
- },
24+
files: [
25+
'<%%= yeoman.app %>/{,*/}*.html',
26+
'.tmp/styles/{,*/}*.css',<% if (coffee) { %>
27+
@@ -77,52 +71,51 @@ module.exports = function (grunt) {
28+
},
29+
30+
// The actual grunt server settings
31+
- connect: {
32+
- options: {
33+
- port: 9000,
34+
- // Change this to '0.0.0.0' to access the server from outside.
35+
- hostname: 'localhost',
36+
- livereload: 35729
37+
- },
38+
+ browserSync: {
39+
livereload: {
40+
+ bsFiles: {
41+
+ src: [
42+
+ '<%%= yeoman.app %>/{,*/}*.html',
43+
+ '.tmp/styles/{,*/}*.css',
44+
+ '<%%= yeoman.app %>/scripts/{,*/}*.js',
45+
+ '<%%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
46+
+ ]
47+
+ },
48+
options: {
49+
- open: true,
50+
- middleware: function (connect) {
51+
- return [
52+
- connect.static('.tmp'),
53+
- connect().use(
54+
- '/bower_components',
55+
- connect.static('./bower_components')
56+
- ),
57+
- connect().use(
58+
- '/app/styles',
59+
- connect.static('./app/styles')
60+
- ),
61+
- connect.static(appConfig.app)
62+
- ];
63+
+ watchTask: true,
64+
+ server: {
65+
+ baseDir: [appConfig.app, '.tmp'],
66+
+ routes: {
67+
+ '/bower_components': 'bower_components'
68+
+ }
69+
}
70+
}
71+
},
72+
- test: {
73+
+ dist: {
74+
+ bsFiles: {
75+
+ src: '<%%= yeoman.dist %>/{,*/}*.html'
76+
+ },
77+
options: {
78+
- port: 9001,
79+
- middleware: function (connect) {
80+
- return [
81+
- connect.static('.tmp'),
82+
- connect.static('test'),
83+
- connect().use(
84+
- '/bower_components',
85+
- connect.static('./bower_components')
86+
- ),
87+
- connect.static(appConfig.app)
88+
- ];
89+
+ server: {
90+
+ baseDir: appConfig.dist
91+
}
92+
}
93+
},
94+
- dist: {
95+
+ test: {
96+
+ bsFiles: {
97+
+ src: 'test/spec/{,*/}*.js'
98+
+ },
99+
options: {
100+
- open: true,
101+
- base: '<%%= yeoman.dist %>'
102+
+ watchTask: true,
103+
+ port: 9001,
104+
+ open: false,
105+
+ logLevel: 'silent',
106+
+ server: {
107+
+ baseDir: ['test', '.tmp', appConfig.app],
108+
+ routes: {
109+
+ '/bower_components': 'bower_components'
110+
+ }
111+
+ }
112+
}
113+
}
114+
},
115+
@@ -489,9 +482,9 @@ module.exports = function (grunt) {
116+
});
117+
118+
119+
- grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
120+
+ grunt.registerTask('serve', 'Compile then start a BrowserSync web server', function (target) {
121+
if (target === 'dist') {
122+
- return grunt.task.run(['build', 'connect:dist:keepalive']);
123+
+ return grunt.task.run(['build', 'browserSync:dist']);
124+
}
125+
126+
grunt.task.run([
127+
@@ -499,7 +492,7 @@ module.exports = function (grunt) {
128+
'wiredep',
129+
'concurrent:server',
130+
'autoprefixer:server',
131+
- 'connect:livereload',
132+
+ 'browserSync:livereload',
133+
'watch'
134+
]);
135+
});
136+
@@ -514,7 +507,7 @@ module.exports = function (grunt) {
137+
'wiredep',
138+
'concurrent:test',
139+
'autoprefixer',
140+
- 'connect:test',
141+
+ 'browserSync:test',
142+
'karma'
143+
]);
144+
145+
diff --git a/templates/common/root/_package.json b/templates/common/root/_package.json
146+
index 6a62991..f2cce83 100644
147+
--- a/templates/common/root/_package.json
148+
+++ b/templates/common/root/_package.json
149+
@@ -11,7 +11,6 @@
150+
"grunt-contrib-coffee": "^0.12.0",<% } %><% if (compass) { %>
151+
"grunt-contrib-compass": "^1.0.0",<% } %>
152+
"grunt-contrib-concat": "^0.5.0",
153+
- "grunt-contrib-connect": "^0.9.0",
154+
"grunt-contrib-copy": "^0.7.0",
155+
"grunt-contrib-cssmin": "^0.12.0",
156+
"grunt-contrib-htmlmin": "^0.4.0",
157+
@@ -19,6 +18,7 @@
158+
"grunt-contrib-jshint": "^0.11.0",
159+
"grunt-contrib-uglify": "^0.7.0",
160+
"grunt-contrib-watch": "^0.6.1",
161+
+ "grunt-browser-sync": "^2.0.0",
162+
"grunt-filerev": "^2.1.2",
163+
"grunt-google-cdn": "^0.4.3",
164+
"grunt-newer": "^1.1.0",

templates/common/root/_Gruntfile.js

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ module.exports = function (grunt) {
5555
},<% } else { %>
5656
js: {
5757
files: ['<%%= yeoman.app %>/scripts/{,*/}*.js'],
58-
tasks: ['newer:jshint:all', 'newer:jscs:all'],
59-
options: {
60-
livereload: '<%%= connect.options.livereload %>'
61-
}
58+
tasks: ['newer:jshint:all', 'newer:jscs:all']
6259
},
6360
jsTest: {
6461
files: ['test/spec/{,*/}*.js'],
@@ -76,9 +73,6 @@ module.exports = function (grunt) {
7673
files: ['Gruntfile.js']
7774
},
7875
livereload: {
79-
options: {
80-
livereload: '<%%= connect.options.livereload %>'
81-
},
8276
files: [
8377
'<%%= yeoman.app %>/{,*/}*.html',
8478
'.tmp/styles/{,*/}*.css',<% if (coffee || typescript) { %>
@@ -89,52 +83,51 @@ module.exports = function (grunt) {
8983
},
9084

9185
// The actual grunt server settings
92-
connect: {
93-
options: {
94-
port: 9000,
95-
// Change this to '0.0.0.0' to access the server from outside.
96-
hostname: 'localhost',
97-
livereload: 35729
98-
},
86+
browserSync: {
9987
livereload: {
88+
bsFiles: {
89+
src: [
90+
'<%%= yeoman.app %>/{,*/}*.html',
91+
'.tmp/styles/{,*/}*.css',
92+
'<%%= yeoman.app %>/scripts/{,*/}*.js',
93+
'<%%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
94+
]
95+
},
10096
options: {
101-
open: true,
102-
middleware: function (connect) {
103-
return [
104-
connect.static('.tmp'),
105-
connect().use(
106-
'/bower_components',
107-
connect.static('./bower_components')
108-
),
109-
connect().use(
110-
'/app/styles',
111-
connect.static('./app/styles')
112-
),
113-
connect.static(appConfig.app)
114-
];
97+
watchTask: true,
98+
server: {
99+
baseDir: [appConfig.app, '.tmp'],
100+
routes: {
101+
'/bower_components': 'bower_components'
102+
}
115103
}
116104
}
117105
},
118-
test: {
106+
dist: {
107+
bsFiles: {
108+
src: '<%%= yeoman.dist %>/{,*/}*.html'
109+
},
119110
options: {
120-
port: 9001,
121-
middleware: function (connect) {
122-
return [
123-
connect.static('.tmp'),
124-
connect.static('test'),
125-
connect().use(
126-
'/bower_components',
127-
connect.static('./bower_components')
128-
),
129-
connect.static(appConfig.app)
130-
];
111+
server: {
112+
baseDir: appConfig.dist
131113
}
132114
}
133115
},
134-
dist: {
116+
test: {
117+
bsFiles: {
118+
src: 'test/spec/{,*/}*.js'
119+
},
135120
options: {
136-
open: true,
137-
base: '<%%= yeoman.dist %>'
121+
watchTask: true,
122+
port: 9001,
123+
open: false,
124+
logLevel: 'silent',
125+
server: {
126+
baseDir: ['test', '.tmp', appConfig.app],
127+
routes: {
128+
'/bower_components': 'bower_components'
129+
}
130+
}
138131
}
139132
}
140133
},
@@ -571,9 +564,9 @@ module.exports = function (grunt) {
571564
});
572565

573566

574-
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
567+
grunt.registerTask('serve', 'Compile then start a BrowserSync web server', function (target) {
575568
if (target === 'dist') {
576-
return grunt.task.run(['build', 'connect:dist:keepalive']);
569+
return grunt.task.run(['build', 'browserSync:dist']);
577570
}
578571

579572
grunt.task.run([
@@ -582,7 +575,8 @@ module.exports = function (grunt) {
582575
'tsd:refresh',<% } %>
583576
'concurrent:server',
584577
'postcss:server',
585-
'connect:livereload',
578+
'autoprefixer:server',
579+
'browserSync:livereload',
586580
'watch'
587581
]);
588582
});
@@ -598,7 +592,8 @@ module.exports = function (grunt) {
598592
'tsd:refresh',<% } %>
599593
'concurrent:test',
600594
'postcss',
601-
'connect:test',
595+
'autoprefixer',
596+
'browserSync:test',
602597
'karma'
603598
]);
604599

templates/common/root/_package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
"grunt-contrib-coffee": "^0.12.0",<% } %><% if (compass) { %>
3737
"grunt-contrib-compass": "^1.0.0",<% } %>
3838
"grunt-contrib-concat": "^0.5.0",
39-
"grunt-contrib-connect": "^0.9.0",
4039
"grunt-contrib-copy": "^0.7.0",
4140
"grunt-contrib-cssmin": "^0.12.0",
4241
"grunt-contrib-htmlmin": "^0.4.0",
4342
"grunt-contrib-imagemin": "^1.0.0",
4443
"grunt-contrib-jshint": "^0.11.0",
4544
"grunt-contrib-uglify": "^0.7.0",
4645
"grunt-contrib-watch": "^0.6.1",
46+
"grunt-browser-sync": "^2.0.0",
4747
"grunt-filerev": "^2.1.2",
4848
"grunt-google-cdn": "^0.4.3",<% if (!coffee) { %>
4949
"grunt-jscs": "^1.8.0",<% } %>

0 commit comments

Comments
 (0)