@@ -17,6 +17,27 @@ module.exports = function (grunt) {
1717 app : require ( './bower.json' ) . appPath || 'app' ,
1818 dist : 'dist'
1919 } ,
20+ express : {
21+ options : {
22+ port : process . env . PORT || 9000
23+ } ,
24+ dev : {
25+ options : {
26+ script : 'server.js'
27+ }
28+ } ,
29+ prod : {
30+ options : {
31+ script : 'server.js' ,
32+ node_env : 'production'
33+ }
34+ }
35+ } ,
36+ open : {
37+ server : {
38+ url : 'http://localhost:<%%= express.options.port %>'
39+ }
40+ } ,
2041 watch : {
2142 coffee : {
2243 files : [ '<%%= yeoman.app %>/scripts/{,*/}*.coffee' ] ,
@@ -30,20 +51,24 @@ module.exports = function (grunt) {
3051 files : [ '<%%= yeoman.app %>/styles/{,*/}*.{scss,sass}' ] ,
3152 tasks : [ 'compass:server' , 'autoprefixer' ]
3253 } , < % } % >
54+ express : {
55+ files : [
56+ '<%%= yeoman.app %>/{,*//*}*.html' ,
57+ '{.tmp,<%= yeoman.app %>}/styles/{,*//*}*.css' ,
58+ '{.tmp,<%= yeoman.app %>}/scripts/{,*//*}*.js' ,
59+ '<%%= yeoman.app %>/images/{,*//*}*.{png,jpg,jpeg,gif,webp,svg}' ,
60+ 'server.js' ,
61+ 'server/{,*//*}*.{js,json}'
62+ ] ,
63+ tasks : [ 'express:dev' ] ,
64+ options : {
65+ livereload : true ,
66+ nospawn : true //Without this option specified express won't be reloaded
67+ }
68+ } ,
3369 styles : {
3470 files : [ '<%%= yeoman.app %>/styles/{,*/}*.css' ] ,
3571 tasks : [ 'copy:styles' , 'autoprefixer' ]
36- } ,
37- livereload : {
38- options : {
39- livereload : '<%%= connect.options.livereload %>'
40- } ,
41- files : [
42- '<%%= yeoman.app %>/{,*/}*.html' ,
43- '.tmp/styles/{,*/}*.css' ,
44- '{.tmp,<%%= yeoman.app %>}/scripts/{,*/}*.js' ,
45- '<%%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
46- ]
4772 }
4873 } ,
4974 autoprefixer : {
@@ -57,38 +82,6 @@ module.exports = function (grunt) {
5782 } ]
5883 }
5984 } ,
60- connect : {
61- options : {
62- port : 9000 ,
63- // Change this to '0.0.0.0' to access the server from outside.
64- hostname : 'localhost' ,
65- livereload : 35729
66- } ,
67- livereload : {
68- options : {
69- open : true ,
70- base : [
71- '.tmp' ,
72- '<%%= yeoman.app %>'
73- ]
74- }
75- } ,
76- test : {
77- options : {
78- port : 9001 ,
79- base : [
80- '.tmp' ,
81- 'test' ,
82- '<%%= yeoman.app %>'
83- ]
84- }
85- } ,
86- dist : {
87- options : {
88- base : '<%%= yeoman.dist %>'
89- }
90- }
91- } ,
9285 clean : {
9386 dist : {
9487 files : [ {
@@ -324,16 +317,21 @@ module.exports = function (grunt) {
324317 }
325318 } ) ;
326319
320+ grunt . registerTask ( 'express - keepalive ', 'Keep grunt running ', function ( ) {
321+ this . async ( ) ;
322+ } );
323+
327324 grunt.registerTask('server', function (target) {
328325 if ( target === 'dist' ) {
329- return grunt . task . run ( [ 'build' , 'connect:dist: keepalive' ] ) ;
326+ return grunt . task . run ( [ 'build' , 'express:prod' , 'open' , 'express- keepalive'] ) ;
330327 }
331328
332329 grunt.task.run([
333330 'clean:server',
334331 'concurrent:server',
335332 'autoprefixer',
336- 'connect:livereload',
333+ 'express:dev',
334+ 'open',
337335 'watch'
338336 ]);
339337 } ) ;
@@ -342,7 +340,6 @@ module.exports = function (grunt) {
342340 'clean:server' ,
343341 'concurrent:test' ,
344342 'autoprefixer' ,
345- 'connect:test' ,
346343 'karma'
347344 ] ) ;
348345
0 commit comments