I use a grunt watch task to handle a Spring Tools Maven project. Here is part of the code that updates the grunt run server (which is dependent on the STS tc server). Just Google “grunt watch” for guidelines on setting up something like this.
// Watches files for changes and runs tasks based on the changed files
watch: {
less: {
files: '<%= config.app %>/styles/{,*/}*.less', '<%= config.app %>/bower_components/{,*/}*.{less}'],
tasks: 'less:server','buildBootstrap','autoprefixer']
},
bower: {
files: 'bower.json'],
tasks: 'bowerInstall']
},
js: {
files: '<%= config.app %>/js/**/*.js'],
tasks: 'jshint'],
options: {
livereload: true
}
},
jstest: {
files: 'test/spec/{,*/}*.js'],
tasks: 'test:watch']
},
gruntfile: {
files: 'Gruntfile.js']
},
styles: {
files: '<%= config.app %>/styles/**/*.css'],
tasks: 'copy:styles', 'copy:vendorstyles', 'autoprefixer']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files:
'<%= config.app %>/templates/**/*.html',
'.tmp/styles/{,*/}*.css',
'<%= config.app %>/images/{,*/}*',
'{.tmp,<%= config.app %>}/scripts/**/*.js',
]
}
},
// The actual grunt server settings
connect: {
options: {
port: 9000,
open: true,
livereload: 35729,
// Change this to '0.0.0.0' to access the server from outside
hostname: 'localhost'
},
livereload: {
options: {
middleware: function(connect) {
return
connect.static('.tmp'),
connect().use('/<%= config.app %>/bower_components', connect.static('./<%= config.app %>/bower_components')),
connect.static(config.app)
];
}
}
},
test: {
options: {
open: false,
port: 9001,
middleware: function(connect) {
return
connect.static('.tmp'),
connect.static('test'),
connect().use('/<%= config.app %>/bower_components', connect.static('./<%= config.app %>/bower_components')),
connect().use('/<%= config.app %>/test/bower_components', connect.static('./<%= config.app %>/test/bower_components')),
connect.static(config.app)
];
}
}
},
dist: {
options: {
base: '<%= config.dist %>',
livereload: false
}
}
},