How do I exclude specific folders and files to be uploaded to S3 using Laravel Mix and Webpack?
I tried this solution https://laracasts.com/discuss/channels/laravel/laravel-mix-upload-files-to-s3 and https://medium.com/@avosalmon/cache-busting-using-laravel-mix-and-cloudfront-s3-eb222b569f88 but it's not doing what I want to do.
const mix = require('laravel-mix');
const S3Plugin = require('webpack-s3-plugin');
require('dotenv').config();
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel applications. By default, we are compiling the CSS
| file for the application as well as bundling up all the JS files.
|
*/
let webpackPlugins = [];
if (mix.inProduction()) {
webpackPlugins = [
new S3Plugin({
include: /.*\.(css|js|ico|jpg|png)$/,
s3Options: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: process.env.AWS_DEFAULT_REGION,
// endpoint: process.env.AWS_ENDPOINT,
},
s3UploadOptions: {
Bucket: process.env.AWS_BUCKET,
CacheControl: 'public, max-age=31536000'
},
directory: 'public',
})
];
}
mix.js('resources/js/alpine.js', 'public/js')
.js('resources/js/choices.js', 'public/js')
.js('resources/js/clipboard.js', 'public/js')
.js('resources/js/notyf.js', 'public/js');
mix.postCss('resources/css/app.css', 'public/css', [
require("tailwindcss"),
]);
mix.disableSuccessNotifications();
mix.webpackConfig({
plugins: webpackPlugins
});
mix.version();
When I run this code, it uploads all contents and folders with css, js, ico, jpg and png files. However, I want to exclude specific folder regardless if it contains (css, js, ico, jpg and png) files.
Example folders inside the public directory
- avatars (needs to be excluded regardless of the file types inside)
- css
- images
- js
- index.php (excluded)
- favicon.ico
CodePudding user response:
I think that you can use CopyWebpackPlugin
to move your files from the build/static directory, to your compiled destination. You don't need to put your files in the source directory, but in a folder that you copy: