HTML and CSS Reference
This is how you load tasks into Grunt. The module you just installed into your script will now be imported.
To configurethe module, you will need to make a new task. Add the following code below the line with pkg: grunt.
file.readJSON . Make sure that you add a comma to that line first, because you are adding the code to an existing
JSON object. The code should look like this:
As you can see, the connect task has its own configuration object. You name the configuration after the task
name, and, in this case, you call it connect. Connect accepts several configuration objects. For this example, you are
simply going to register a port number and base it on where the root of the server should host. Here, this will be inside
the current directory. Also, for this example, you need to set the keepalive property to true . Connect will only run so
long as Grunt is running, so without this, the build script would execute, and the server would be shut down.
Now, at the end of the line of code, just before the closing curly brace, add the following code:
To run a task, you have to set a task name. Here, you are using default and an array to list the tasks to run, and you
are only calling connect. Default is the main task that this script will run, and, as you can probably guess, it will run
whenever you call the script. You can create all kinds of tasks with their own unique names. Later on, I'll show you
some ways to configure and run them. Before you can run this script, you need to create an index.html page for the
server to load. Add the following code to the document:
<meta charset="utf-8" />
<title>Grunt Demo Project</title>
Now that you have a file to load, go back to the command line, and enter the following command:
This is how you run the build script. The code will automatically call the default task. You should see the server
start up at the command prompt, as shown in Figure 23-10 .