Last active
July 9, 2022 18:24
-
-
Save avosalmon/ebb98f7303cd842050b2583265ff1aea to your computer and use it in GitHub Desktop.
Upload assets to S3 using Laravel Mix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mix = require('laravel-mix'); | |
const s3Plugin = require('webpack-s3-plugin'); | |
/* | |
|-------------------------------------------------------------------------- | |
| Mix Asset Management | |
|-------------------------------------------------------------------------- | |
| | |
| Mix provides a clean, fluent API for defining some Webpack build steps | |
| for your Laravel application. By default, we are compiling the Sass | |
| file for the application as well as bundling up all the JS files. | |
| | |
*/ | |
let webpackPlugins = []; | |
if (mix.inProduction() && process.env.UPLOAD_S3) { | |
webpackPlugins = [ | |
new s3Plugin({ | |
include: /.*\.(css|js)$/, | |
s3Options: { | |
accessKeyId: process.env.AWS_KEY, | |
secretAccessKey: process.env.AWS_SECRET, | |
region: 'ap-northeast-1', | |
}, | |
s3UploadOptions: { | |
Bucket: process.env.ASSETS_S3_BUCKET, | |
CacheControl: 'public, max-age=31536000' | |
}, | |
basePath: 'app', | |
directory: 'public' | |
}) | |
] | |
} | |
mix.js('resources/js/app.js', 'public/js') | |
.sass('resources/sass/app.scss', 'public/css'); | |
mix.webpackConfig({ | |
plugins: webpackPlugins | |
}); | |
if (mix.inProduction()) { | |
mix.version(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment