Skip to content
nimbupani edited this page Aug 7, 2012 · 1 revision

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 socket.io server instance is created while a client-side sciprt is injected dynamically on response (eg. it won't edit the generated file)

Helpers

server

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 serve.io helpers below.

serve.io

serve.io creates and returns a webserver and setup a socket.io instance and the "inject" middleware. /socket.io/socket.io.js and /reload.js are then available.

task.helper('serve.io', config);

serve

serve same as serve.io, without the socket.io connection and inject middleware.

task.helper('serve.io', config);

inject.io

inject.io 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('inject.io', config))
  .use(connect.static);

app.listen(3000);

» 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