1. What is Grunt?
2. Download Node.js
3. Basic Command Line Commands
If you have not used command line terminal before you here are some basic commands:
Description: Lists the names of the files in the working directory.
For more complete information use
Description: Changes the working directory to the one you named.
Description: Brings you up one directory level.
Description: Returns you to your home directory.
Description: Displays the pathname of the current directory.
Description: Makes a new directory
4. Install Grunt
- Open your preferred terminal or install iTerm.
- Install Grunt globally: instructions below will install grunt client globally on your machine, if you already have Grunt installed skip this step. For a more detailed explanation see the official documentation.
- Install Grunt locally: Now we will install Grunt locally specifically for this project. Go to your project folder. Replace the path after
cdwith the path to your folder:
In the terminal type out the below command to get to the project folder (if you have saved the workshop folder elsewhere adjust the path):
npm install grunt –save-dev
To configure the project, within your project folder type
npm init in the terminal and follow the instructions:
6. Grunt AWS Plugin
We will now install Grunt AWS Plugin. Grunt uses different plugins to perform certain tasks, in order to deploy to Amazon S3 we will use the grunt-aws-s3 plugin.
In your project folder we can install this using the command below:
npm install grunt-aws-s3 –save-dev
We now have the plugin installed and we can configure grunt to use this task to deploy our project without having to manually upload the files every time.
In order for us to use this plugin and deploy to S3 in the command line we need to create a file called
s3settings.json, here we will keep all the login details and bucket information. This file MUST be kept secret, do not commit it to github or any other version control system. It should be excluded in
.gitignorefile if you are using git. It is important to take care as if these details are made public your account may be accessed and used by someone else, leaving you with a bill to pay:
secret are available in the user credentials file you downloaded when creating an IAM user. Bucket must be exactly what you called the bucket on Amazon S3 and the same for region.
The second file we need to create is
Gruntfile.js this is a default file Grunt will look for locally within the project folder. Here is where we configure the tasks.
Using your text editor or command line, create a new file within the workshop folder called
Gruntfile.js, the content of it should be the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Here we have configured the plugin to upload to Amazon S3 all files in the folder deploy, so we would now have to create this folder within the project and copy any files we want uploaded.
We have also created a task called
deploy which can be run in command line within the project folder to upload all files within deploy folder to Amazon S3, to the bucket specified in the
7. Use Grunt to deploy to S3
Go to the project folder in the terminal. You can now run the deploy command by typing:
And we are done!