1.0.2 • Published 2 years ago

vite-plugin-s3 v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Upgrading to 1.0.0

There are breaking changes in the latest release of 1.0.0

You must use the named import now for the plugin instead of the default export.

import { viteS3 } from 'vite-plugin-s3';

This plugin will upload all built assets to s3.

This package was heavily inspired by webpack-s3-plugin and also Laravel vapor's asset deployment.

Install Instructions

$ npm i vite-plugin-s3

$ yarn add vite-plugin-s3
Import vite-plugin-s3 in your vite config file and add it as a vite plugin.
import { viteS3 } from 'vite-plugin-s3';

export default defineConfig({
    plugins: [
        viteS3({
            s3Options: {
                accessKeyId: process.env.AWS_ACCESS_KEY_ID,
                secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
                region: 'us-east-1'
            },
            s3UploadOptions: {
                Bucket: 'dist-cdn',
            },
        }),
    ]
});
Config Example
viteS3({
    exclude: /.*\.img/,
    include: /.*\.js$/,
    uploadEnabled: !!process.env.UPLOAD_ENABLED,
    s3Options: {
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
        region: 'us-east-1'
    },
    s3UploadOptions: {
        Bucket: 'dist-cdn',
    },
    basePath: 'production',
})

Options

OptionTypeDefaultDescription
uploadEnabledBooleantrueThis setting can be used to disable or enable the uploading of assets
excludeStringA Regex Pattern to match for excluded content
includeStringA Regex Pattern to match for included content. Behaves the same as exclude
s3OptionsObjectUpload options for s3Config
s3UploadOptionsObjectUpload options for putObject
basePathStringThe root namespace of uploaded files on S3
hasherFunctionCustomize the behavior of how the manifest file gets hashed
onFinishedFunctionThis callback will be invoked after all operations are complete. The parameters passed are the instance of the s3 client used for uploading, the plugin config, and the manifest file hash
enforceStringpostCustomize the enforce parameter of the vite plugin
uploadDirStringconfig.root/config.build.outDirThe folder containing the assets you want to upload

Example Usage

$ UPLOAD_ENABLED=true AWS_ACCESS_KEY_ID=******* AWS_SECRET_ACCESS_KEY=******** yarn prod

image

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.4.0

2 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.2

3 years ago