function asset({ when = true, test, name, loaders = [] }) {
        if (!when) {
            return [];
        }

        if (mix.config.assetModules) {
            return [
                {
                    test,
                    type: 'asset/resource',
                    generator: {
                        /**
                         *
                         * @param {any} pathData
                         * @returns
                         */
                        filename: pathData =>
                            name(pathData, { dirs: mix.config.assetDirs }),
                        publicPath: mix.config.resourceRoot
                    },
                    use: loaders
                }
            ];
        }

        return [
            {
                test,
                use: [
                    {
                        loader: mix.resolve('file-loader'),
                        options: {
                            // we're somewhat mimic-ing the asset module API here to simply name resolution further down
                            /**
                             *
                             * @param {string} path
                             */
                            name: path =>
                                name(
                                    { filename: path },
                                    {
                                        dirs:
                                            mix.config.fileLoaderDirs ||
                                            mix.config.assetDirs
                                    }
                                ).replace('[ext]', '.[ext]'),
                            publicPath: mix.config.resourceRoot
                        }
                    },
                    ...loaders
                ]
            }
        ];
    }
@param {object} param0
@param {boolean} [param0.when]
@param {RegExp} param0.test
@param {(data: *, meta: { dirs: Record<string, string>}) => string} param0.name
@param {import("webpack").RuleSetUseItem[]} [param0.loaders]
@returns {import("webpack").RuleSetRule[]}