M
M
Mike2016-02-01 17:32:30
JavaScript
Mike, 2016-02-01 17:32:30

How to properly use the NPM package grunt-aws?

You need to set up uploading the code to a remote server that is running on Amazon.
What I did:
1) Added the package to package.json
2) Installed the package using the npm install command
3) Configured the Grunt config
4) Launched Grunt
Configured it like this:

aws: grunt.file.readJSON("aws-credentials.json"),
s3: {
    options: {
        accessKeyId: "<%= aws.accessKeyId %>",
        secretAccessKey: "<%= aws.secretAccessKey %>",
        bucket: "my-awesome-bucket"
    },
    build: {
        cwd: "public/",
        src: "**"
    }
}

grunt.loadNpmTasks('grunt-aws');

grunt.registerTask('default', ['aws']);

Gives an error message
Warning: Task "aws" not found. Use --force to continue.

Why and what to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mike, 2016-02-03
@ddale

Short description.
From Amazon, you get accessKeyId and secretAccessKey, which you write to a separate file. Next, add the name and version of the package to package.json, then add the necessary descriptions and calls to gruntfile.js , install the package, run Grunt.
1) Add to package.json
2) Create credentials.json file next to package.json and gruntfile.js

{
  "accessKeyId": "Здесь ID",
  "secretAccessKey": "Здесь ключ"
}

3) Add to gruntfile.js
// package.json
pkg: grunt.file.readJSON('package.json'),

// Переменные каталогов проекта
project: {
    app:    ['public'],
    assets: ['<%= project.app %>/assets'],
},

// Проталкивание файлов на S3
aws: grunt.file.readJSON("credentials.json"),
s3: {
    options: {
        accessKeyId: "<%= aws.accessKeyId %>",
        secretAccessKey: "<%= aws.secretAccessKey %>",
        bucket: "имя-каталога-куда-лить"
    },
    upload: {
        headers: {
            CacheControl: 604800
            // Expires: new Date(Date.now() + 604800000).toUTCString()
        },
        cwd: ".",
        src: [
            "<%= project.app %>/*.html",
            "<%= project.app %>/dist/**",
            "<%= project.assets %>/fonts/**",
            "<%= project.assets %>/img/*"
        ]
    }
},

// Загрузка предварительно установленного модуля
grunt.loadNpmTasks('grunt-aws');

// Задания будут выполнятся сразу после команды grunt
grunt.registerTask('default', [ 's3']);

4) Open the terminal, go to the directory with the project and execute two commands
npm install
grunt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question