Time for action – compiling a template using Pistachio
Create a new template file and eventually compress it using Pistachio. Follow the given steps:
Open your command-line tool and move to the folders containing the template files.
Type the
pistachio
command and specify the name of the output file and the file to compile:$ pistachio --out=splash-tpl.js splash-tpl.html
Create a build file named, for instance,
template-build.js
, for the existing template to use when compressing the file with UglifyJS2, specifying the template name and the desired output filename:({ name: ‘splash-tpl', out: ‘splash-built.js' })
Run the r.js Node module from the command-line tool:
$ r.js -o template-build.js
Open the file and check its syntax and size.
What just happened?
You created a compressed version of the template file that is stored in a variable. You can now request it in the modules of the app and avoid any unnecessary XMLHttpRequest.
This technique is most beneficial when working with pretty...