Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lookdee's avatar

Push Vite JS/CSS assets to S3

Is there a way to push JS/CSS assets compiled during build to S3? I have an app that's using S3 for asset files (profile photos, misc uploaods) and ASSET_URL env is pointing to that bucket so we can use asset('profiles/user123.jpg');. Since Vite's @vite('reosurces/js/app.js') directive uses that same helper in the backend to figure out paths to JS/CSS is there a way to push those files to S3 (or a way to tell Vite where to look for them)?

0 likes
1 reply
JakeCausier's avatar

You could use the AWS CLI linked into an NPM script:

aws s3 sync ./dist s3://bucket-name --delete

Simply change the /dist soruce folder path to your compiled assets and the S3 bucket to where you want them stored. The --delete flag will replace the existing files in the bucket with your new versions.

You can see a full reference of AWS CLI commands for S3 here: https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/index.html

Please or to participate in this conversation.