nimbupani edited this page Aug 7, 2012 · 1 revision

» Home

» Tasks

» clean: Wipe the previous build dirs.

» mkdirs: Prepares the build dirs.

» concat: Concatenate files. (built-in)

» css: Concats, replaces @imports and minifies CSS files.

» min: Minify files using UglifyJS (built-in)

» rev: Automate the revving of assets and perform the hash rename

» usemin: Replaces references to non-minified scripts / stylesheets

» serve: Spawns up a basic local http server

» connect: livereload version of serve task

Clone this wiki locally

Task - server

server is a utility task to start a local http server on top of generated build dirs, possibly intermediate/ and publish/ on different ports.

It overrides the build-in grunt helper following the foundation as described in grunt's documentation

serve: {
  staging: { port: 3000, base: 'intermediate/' },
  output: { port: 3001, base: 'publish/' }

If --reload cli option is used when grunt serve is run, a server instance is created while a client-side sciprt is injected dynamically on response (eg. it won't edit the generated file)



server creates and returns a basic application server, a configuration object may be passed where:

  • base - is the base directory to server static file from
  • port - server listen to this port
task.helper('serve', config);

This helper is used by the serve and helpers below. creates and returns a webserver and setup a instance and the "inject" middleware. / and /reload.js are then available.

task.helper('', config);


serve same as, without the connection and inject middleware.

task.helper('', config); is a grunt helper returning a valid connect / express middleware. It's job is to setup a middleware right before the usual static one, and to bypass the response of .html file to render them with additional scripts.

var app = connect()
  .use(task.helper('', config))