Vite does not natively support wildcards for file inputs in the same way that Webpack Mix does. However, you can achieve a similar result by dynamically generating the list of files using Node.js functions. Here's how you can modify your Vite configuration to include all files in the resources/css/pages/ directory:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import { readdirSync } from 'fs';
import { resolve } from 'path';
// Function to get all files from a directory
function getFilesFromDir(dir, fileTypes) {
const filesToReturn = [];
function walkDir(currentPath) {
const files = readdirSync(currentPath);
for (let i in files) {
const curFile = resolve(currentPath, files[i]);
if (readdirSync(curFile, { withFileTypes: true }).some(dirent => dirent.isDirectory())) {
walkDir(curFile);
} else {
if (fileTypes.indexOf(curFile.split('.').pop()) !== -1) {
filesToReturn.push(curFile);
}
}
}
}
walkDir(resolve(__dirname, dir));
return filesToReturn;
}
// Get all .css and .scss files in the directory
const pageStyles = getFilesFromDir('./resources/css/pages', ['css', 'scss']);
export default defineConfig({
server: {
host: '0.0.0.0'
},
plugins: [
laravel({
input: [
'resources/css/app.scss',
...pageStyles, // Spread the array of page styles
'resources/js/app.js',
],
refresh: true,
}),
],
});
In this solution, we define a getFilesFromDir function that recursively reads a directory and returns an array of file paths that match the specified file types. We then call this function to get all .css and .scss files in the resources/css/pages directory and spread them into the input array of the Vite configuration.
This way, you don't have to manually specify each file, and any new files added to the directory will be automatically included in the build process.