I'm still fairly new to Grunt and I've been wondering if it's possible to run both servers on the same port simultaneously. I seem to be encountering some issues with this setup, most likely stemming from the Grunt file.
I am utilizing grunt-contrib-connect and grunt-express-server for their respective functions. Ideally, running grunt server
should start up the connect server, livereload, and the express server.
You can find my Grunt file below. Any help is appreciated!
'use strict';
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
yeoman: {
// configurable paths
app: require('./bower.json').appPath || 'app',
dist: 'dist'
},
watch: {
styles: {
files: ['<%= yeoman.app %>/styles/{,*/}*.{css,less}'],
tasks: ['copy:styles', 'autoprefixer', 'less']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= yeoman.app %>/{,*/}*.html',
'.tmp/styles/{,*/}*.{css,less}',
'{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
}
},
autoprefixer: {
options: ['last 1 version'],
dist: {
files: [{
expand: true,
cwd: '.tmp/styles/',
src: '{,*/}*.css',
dest: '.tmp/styles/'
}]
}
},
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729,
keepalive: true
},
livereload: {
options: {
open: true,
base: [
'.tmp',
'<%= yeoman.app %>'
]
}
},
test: {
options: {
port: 9001,
base: [
'.tmp',
'test',
'<%= yeoman.app %>'
]
}
},
dist: {
options: {
base: '<%= yeoman.dist %>'
}
}
},
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= yeoman.dist %>/*',
'!<%= yeoman.dist %>/.git*'
]
}]
},
server: '.tmp'
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'<%= yeoman.app %>/scripts/{,*/}*.js'
]
},
less: {
development: {
options: {
paths: ["<%= yeoman.app %>/styles"],
yuicompress: true
}
},
files: {
"<%= yeoman.app %>/styles/style.css": "<%= yeoman.app %>/styles/style.less"
}
},
/*shell: {
launchExpress: {
command: function () {
console.log('Launching the API...');
return 'coffee server.coffee';
},
options: {
stdout: true
}
}
},*/
coffee: {
compile: {
files: {
'./server.js': './server.coffee'
}
}
},
express: {
options: {
// Override defaults here
},
dev: {
options: {
script: './server.js'
}
},
prod: {
options: {
script: './server.js',
node_env: 'production'
}
},
test: {
options: {
script: './server.js'
}
}
},
// ...
grunt.registerTask('default', [
'jshint',
'test',
'build'
]);
};