HTML and CSS Reference
In-Depth Information
At this point, you have seen the basic steps for creating a build script with Grunt. You find the task module you
want to install with npm, import it into your GruntFile, create a configuration object for it, and then add it to your task
or make a new one for it. Next, I'll talk about the process I go through when creating a build script and what is useful
for HTML5 games.
What Should Your Build Script Do?
Sometimes, the most difficult part of creating a build script is just figuring out what you need it to do without trying to
boil the ocean. At the heart of all my HTML5 game build scripts are the following tasks:
Copy source code to a tmp folder so that I don't make changes to the original source code
or mess anything up.
Combine all JavaScript into a single JavaScript file.
Inject JSON and other external data into my combined code to cut down on unnecessary
external connections and additonal load times.
Uglify and minimize to a single JavaScript file.
Delete any unnecessary files.
Perform builds for each platform to which I want to deploy the game.
As you can see, there isn't a lot here. Each step is critical to the end result, which is packaging the game and
getting it ready to publish to a server or app store. From here, there may be subtle variations that you want to do,
based on the framework that you are using.
To see how this sort of build script works with an actual project, I suggest you see Chapter 19 . This chapter walks
you through how to build a simple, rogue-like game, using TypeScript. Its build process is fully automated, taking
advantage of all the content covered in this chapter.
Creating build scripts, or any kind of automated workflow, takes a good deal of work. It's not difficult work, mind you,
just a lot of planning and thought on how to build out a robust automation plan as well as how to scale up or down to
fit your ever-changing needs.
Over time, you will start to understand better how to break apart your scripts to make them more modular and
reusable across all your projects. Creating build scripts is an art form all its own and an integral part of any serious
developer's workflow. The time saved on packaging and deploying games alone is worth the up-front investment in
making the build script. I wouldn't work on a single HTML5 game without some form of build script, even if it only
compressed the JavaScript and minified it before uploading.
Search WWH ::

Custom Search