You install templates into a folder in your home folder. This will be ~/.grunt_init/ on OS X and Linux, and %USERPROFILE%.grunt-init on Windows. Typically, since these templates are often located on GitHub, you’ll use Git to clone the template into that folder. If you don’t have the Git client installed, you can get installers for your operating system at the Git website.[19]
Let’s clone the grunt-init-grunt template, which makes creating a new Gruntfile easy. First, we clone the template file to our machine’s ~/.grunt-init/ folder. Open a new Terminal and ensure that you’re in your home folder. Then use Git to clone the grunt-init-gruntfile plug-in into the folder .grunt-init/gruntfile within your home folder:
| $ git clone https://github.com/gruntjs/grunt-init-gruntfile.git |
| .grunt-init/gruntfile |
And now we can try it out. When we run the template we’ll be asked a series of questions, very similar to the ones we get when we use the npm init command. Our answers to the questions determine the values that end up in the Gruntfile and package.json file for the project.
| $ grunt-init gruntfile |
| Running "init:gruntfile" (init) task |
| This task will create one or more files in the current directory, based on the |
| environment and the answers to a few questions. Note that answering "?" to any |
| question will show question-specific help and answering "none" to most questions |
| will leave their values blank. |
| |
| "gruntfile" template notes: |
| This template tries to guess file and directory paths, but you will most likely |
| need to edit the generated Gruntfile.js file before running grunt. If you run |
| grunt after generating the Gruntfile, and it exits with errors, edit the file! |
| |
| Please answer the following: |
| [?] Is the DOM involved in ANY way? (Y/n) n |
| [?] Will files be concatenated or minified? (Y/n) n |
| [?] Will you have a package.json file? (Y/n) y |
| [?] Do you need to make any changes to the above before continuing? (y/N) n |
| |
| Writing Gruntfile.js...OK |
| Writing package.json...OK |
| |
| Initialized from template "gruntfile". |
| |
| Done, without errors. |
We can write our own questions and use those answers to include, exclude, and alter the content of new files. So let’s dig in to creating our own template!
3.145.151.153