排除 Laravel Mix 和 Webpack 中的文件夹和文件

Exclude folders and files in Laravel Mix and Webpack

如何使用 Laravel Mix 和 Webpack 排除要上传到 S3 的特定文件夹和文件?

我试过这个解决方案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,但它没有达到我想要的效果。

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();

当我 运行 此代码时,它会上传包含 css、js、ico、jpg 和 png 文件的所有内容和文件夹。但是,我想排除特定文件夹,无论它是否包含(css、js、ico、jpg 和 png)文件。

public 目录中的示例文件夹

我认为您可以使用 CopyWebpackPlugin 将文件从 build/static 目录移动到编译后的目标位置。您不需要将文件放在源目录中,而是放在您复制的文件夹中:

https://laravel-mix.com/docs/4.0/copying-files