The server task is used to start a static server with an empty base set as the web root.
Example: Serve ./web-root as http://localhost:8080/ :
grunt.initConfig({ server: { port: 8080, base: './web-root' } });
It will function similarly to the Apache server, serving static files based on their path, but using the http module via connect to configure it ( source ).
If you need it to serve more than just static files, you will need to consider the definition of a server user task :
grunt.registerTask('server', 'Start a custom web server.', function() { grunt.log.writeln('Starting web server on port 1234.'); require('./server.js').listen(1234); });
And the user server instance:
// server.js var http = require('http'); module.exports = http.createServer(function (req, res) { // ... });
Can I use mapped / mined server task mapping files to test my application [...]
Concatenation and minimization have their own tasks - concat and min - but can be used together with the server task to complete all 3.
Edit
If you want it to keep the server (as well as grunt) for some time, you could define the task as asynchronous (from the server 'close' event ):
grunt.registerTask('server', 'Start a custom web server.', function() { var done = this.async(); grunt.log.writeln('Starting web server on port 1234.'); require('./server.js').listen(1234).on('close', done); });
Jonathan Lonowski Aug 13 2018-12-12T00: 00Z
source share