The `webpack-s3-plugin` is a specialized Webpack plugin designed to streamline the process of uploading compiled assets from a Webpack build directly to an Amazon S3 bucket. It is currently in a release candidate phase, indicated by version `1.2.0-rc.0`, suggesting ongoing development towards a stable 1.2.0 release. The plugin integrates deeply into the Webpack compilation lifecycle, allowing developers to define precise `include` or `exclude` rules, which can be regular expressions, functions, or arrays of rules, to control which assets are uploaded. It provides extensive configuration options for AWS S3, including credential management, region specification, and S3 object upload parameters like `ACL`. A key differentiator is its focus on handling assets directly from the build output, rather than reading from a local directory post-compilation, for efficiency. It requires `webpack` version 5 or higher as a peer dependency.
npm install webpack-s3-pluginVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates configuring `webpack-s3-plugin` to upload bundled JavaScript and CSS files to a specified S3 bucket. It includes essential S3 authentication and region settings, shows how to define include/exclude rules, and overrides the default ACL to 'private' for enhanced security, leveraging environment variables for sensitive credentials.
Remove the `directory` option from your `S3Plugin` configuration when uploading Webpack build output.
In your `S3Plugin` configuration, set `s3UploadOptions: { ACL: 'private' }` or another appropriate ACL value based on your security requirements.Consider waiting for a stable release (e.g., 1.2.0) for production deployments if maximum stability is critical. Always pin to exact versions in `package.json`.
Verify `s3Options` values are correct. Ensure `process.env.AWS_ACCESS_KEY_ID` and `process.env.AWS_SECRET_ACCESS_KEY` are set in your environment. Check AWS IAM policies for necessary S3 permissions. Using `AWS.SharedIniFileCredentials` for profiles is also an option.
Provide a valid `s3Options` object with `accessKeyId`, `secretAccessKey`, and `region` (or `credentials` object) to the `S3Plugin` constructor.
Review the IAM policy attached to your AWS user or role and ensure it explicitly grants permissions for `s3:PutObject` and `s3:PutObjectAcl` on the target S3 bucket and objects within it.
Verify that your `include` and `exclude` regular expressions or functions correctly match the filenames of the assets you intend to upload. Double-check the `Bucket` name in `s3UploadOptions`.