Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusting file names when uploading to S3 #75

Closed
StasD opened this issue Jun 17, 2017 · 5 comments
Closed

Adjusting file names when uploading to S3 #75

StasD opened this issue Jun 17, 2017 · 5 comments

Comments

@StasD
Copy link

StasD commented Jun 17, 2017

Hi,
Is it possible to adjust file name when uploading to S3?
My current setup is this:

        new CompressionPlugin({
            asset: "[path]",  // "[path].gz[query]"
            algorithm: "gzip",
            test:  /\.(js|css|map)$/,
            // threshold: 10240,
            minRatio: 10  // 0.8
        }),

        new S3Plugin({
            s3Options: {
                accessKeyId: 'xxx',
                secretAccessKey: 'xxx',
                region: 'xxx'
            },
            s3UploadOptions: {
                Bucket: 'xxx',
                ContentEncoding(fileName) {
                    if (/\.(js|css|map)$/.test(fileName)) {
                        return 'gzip';
                    }
                }
            },
            cloudfrontInvalidateOptions: {
                DistributionId: 'xxx',
                Items: ["/*"]
            }
        }),

As you can see, the CompressionPlugin overwrites .js, .css and .map files with their compressed version. Ideally, I would like it to retain the original uncompressed files, but skip them when uploading to S3, and instead upload .js.gz as .js etc. Is this possible to do with your plugin?
Thanks!

@StasD StasD changed the title edede Adjusting file names when uploading to S3 Jun 17, 2017
@MikaAK
Copy link
Owner

MikaAK commented Jun 17, 2017

Add include: /.(js|css)$/, basically use exclude/include to target `

@MikaAK MikaAK closed this as completed Jun 17, 2017
@StasD
Copy link
Author

StasD commented Jun 18, 2017

Hi Mika,
I think you didn't understand my question.
I will actually exclude: /.(js|css|map)$/, not include: them.
But then I need to upload compressed versions of those files to S3 removing the .gz extension, e.g. app.js.gz should become app.js after uploading to S3. Is this possible?

@MikaAK
Copy link
Owner

MikaAK commented Jun 19, 2017

Try asset: "[file]" instead in compression plugin to make compression plugin not add .gz. There's no way to rename files on the fly before upload

@StasD
Copy link
Author

StasD commented Jun 19, 2017

OK, thanks for clarification!
P.S.: asset: "[path]" already doesn't add .gz.

@MikaAK
Copy link
Owner

MikaAK commented Jun 19, 2017

Awesome! I'll try and look into some renaming for file names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants