如何从webpack上传资产到s3

时间:2016-10-11 09:33:42

标签: javascript amazon-s3 webpack

我是webpack的新手。我想使用webpack将我的缩小的js文件上传到s3。我在webpack.config.js文件中使用了以下代码。

   const webpack = require('webpack');
var S3Plugin = require('webpack-s3-plugin');

     module.exports = {
         entry: './src/app.js',
         output: {
             path: './bin',
             filename: 'app.bundle.js'
         },
          plugins: [
            new webpack.optimize.UglifyJsPlugin({
                compress: {
                    warnings: false,
                },
                output: {
                    comments: false,
                },
            }),
            new S3Plugin({
          // Only upload css and js
          include: /.*\.(css|js)/,
          // s3Options are required
          s3Options: {
            accessKeyId: 'key',
            secretAccessKey: 'key',
            region: 'Oregon',
            signatureVersion: 'v4',
     /*       s3BucketEndpoint: true,*/
            endpoint: "endpoint"
          },
          s3UploadOptions: {
            Bucket: 'bucketname'
          }
        })
        ]
     };

但是我在webpack中遇到以下错误 S3Plugin中的错误:错误:AWS.S3中的SigV4不支持非文件流对象我该如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

将signatureVersion更改为v3:

  s3Options: {
    accessKeyId: process.env.AWS_ACCESS_KEY_ID,
    secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
    signatureVersion: 'v3',
    region: 'eu-central-1'
  },

答案 1 :(得分:0)

试试这个s3-plugin-webpack fork:

npm install git + https://github.com/fabianfett/s3-plugin-webpack.git

如作者所建议: https://github.com/MikaAK/s3-plugin-webpack/issues/43#issuecomment-238854713

使用&eu-central-1'进行测试区域。应该使用' us-west-2' (俄勒冈州)。