Skip to content

Commit

Permalink
Added file mime detection and setting for S3.
Browse files Browse the repository at this point in the history
  • Loading branch information
olsgreen committed Jul 31, 2020
1 parent 69ec5c3 commit cd6f852
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webpack-s3-pusher",
"version": "1.0.1",
"version": "1.1.0",
"description": "A webpack plugin that pushes your packed assets to your S3 bucket, no more, no less.",
"main": "webpack.s3.pusher.js",
"scripts": {
Expand All @@ -23,6 +23,7 @@
"license": "MIT",
"dependencies": {
"aws-sdk": "^2.291.0",
"cli-progress": "^3.0.0"
"cli-progress": "^3.0.0",
"mime-types": "^2.1.27"
}
}
9 changes: 4 additions & 5 deletions webpack.s3.pusher.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const AWS = require('aws-sdk');
const fs = require('fs');
const progress = require('cli-progress');
const mime = require('mime-types');

let s3;
let bar;
Expand Down Expand Up @@ -76,11 +77,9 @@ S3PusherPlugin.prototype.upload = function(filename, content) {
Body: content
};

/**
* @todo We should use a MIME sniffer on all files.
*/
if (filename.slice(-3) === 'css') {
params.ContentType = 'text/css';
let contentType = mime.lookup(filename)
if (contentType) {
params.ContentType = contentType;
}

s3.putObject(params, (err, data) => {
Expand Down

0 comments on commit cd6f852

Please sign in to comment.