Skip to content
Chris Wren edited this page Oct 27, 2013 · 2 revisions

GitHub Pages

When deploying to GitHub pages, use the grunt-gh-pages plugin.

First install grunt-gh-pages with this command:

npm install grunt-gh-pages --save-dev

Then copy and paste the following 'gh-pages' config property into your Gruntfile's initConfig call:

grunt.initConfig({
  'gh-pages': {
    options: {
      base: 'dist'
    },
    src: ['**']
  }
});

Finally you can add a deploy task which runs the build task and then pushes to GitHub:

grunt.registerTask('deploy', [
  'build',
  'gh-pages'
]);

Now you can deploy your site by running the grunt deploy command.

Amazon S3

When deploying to Amazon S3, use the grunt-s3 plugin.

First install grunt-s3 with this command:

npm install grunt-s3 --save-dev

Then create a grunt-aws.json file with the following format in the root folder of your site:

{
  "key": "your-aws-key",
  "secret": "your-aws-secret",
  "bucket": "your-s3-bucket"
}

Then copy and paste the following aws and s3 config properties into your Gruntfile's initConfig call:

grunt.initConfig({
  aws: grunt.file.readJSON('./grunt-aws.json'),
  s3: {
    options: {
      key: '<%= aws.key %>',
      secret: '<%= aws.secret %>',
      bucket: '<%= aws.bucket %>',
      access: 'public-read'
    },
    dev: {
      upload: [{
        src: 'dist/**',
        rel: 'dist',
        dest: '/'
      }]
    }
  }
});

Finally you can add a deploy task which runs the build task and then pushes to S3:

grunt.registerTask('deploy', [
  'build',
  's3'
]);

Now you can deploy your site by running the grunt deploy command.

FTP

When deploying via FTP, use the grunt-ftpush plugin.

First install grunt-ftpush with this command:

npm install grunt-ftpush --save-dev

Then create a .ftppass file with the following format in the root folder of your site:

{
  "key": {
    "username": "your-ftp-username",
    "password": "your-ftp-password"
  }
}

Then copy and paste the following ftpush config property into your Gruntfile's initConfig call:

grunt.initConfig({
  ftpush: {
    build: {
      auth: {
        host: 'your-website.com',
        port: 21,
        authKey: 'key'
      },
      src: 'dist',
      dest: 'your-remote-destination-folder',
      simple: true,
      exclusions: ['**.DS_Store']
    }
  }
});

Finally you can add a deploy task which runs the build task and then pushes to your site via ftp:

grunt.registerTask('deploy', [
  'build',
  'ftpush'
]);

Now you can deploy your site by running the grunt deploy command.

Clone this wiki locally