To import all files in a specific folder using Laravel plugin in Vite, you can use the glob package to get all the files in the folder and pass them as an array to the input option in the Vite config.
Here's an example code snippet:
import { defineConfig } from "vite";
import laravel from "laravel-vite-plugin";
import react from "@vitejs/plugin-react";
import path from "path";
import glob from "glob";
export default defineConfig({
plugins: [
laravel({
input: ["resources/js/app.js", ...glob.sync("resources/js/static/*.js")],
refresh: true,
}),
react(),
],
resolve: {
alias: {
"~bootstrap": path.resolve(__dirname, "node_modules/bootstrap"),
"~fontawesome": path.resolve(
__dirname,
"node_modules/@fortawesome/fontawesome-free"
),
"@": "/resources",
},
},
server: {
hmr: {
host: "localhost",
},
},
});
In this example, we use the glob.sync method to get all the files in the resources/js/static folder that match the *.js pattern and spread them into the input array.
Make sure to install the glob package by running npm install glob or yarn add glob.