In my laravel 10 project I load a js as:
@vite(['resources/js/myjs.js'])
And my vite.config.js
contains the follwoing settings
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import inject from "@rollup/plugin-inject";
export default defineConfig({
plugins: [
laravel({
input: [
'resources/css/style.css',
'resources/css/another-style.css',
'resources/js/main.js',
'resources/js/my.js',
'resources/js/myjs.js',
'node_modules/jquery/dist/jquery.js',
'node_modules/bootstrap/dist/css/bootstrap.css',
'node_modules/@fortawesome/fontawesome-free/css/all.css'
],
refresh: true,
}),
inject({
$: 'jquery',
jQuery: 'jquery',
'common_functions':'resources/js/common_functions.js',
}),
],
build: {
rollupOptions: {
external: [
"js/modules/*",
]
}
}
});
But if I need another js file I should place it in vite.config.js
thus makes the divelopment kinda slow because I need to place any new ccs or js into the vite.config.js
that due to rush of development I may forget it.
Is there a way to conveniently for the vite to look any files defined in resources/css
and resources/js
folders?
2
Answers
As @Burak Ayyildiz says you need to manually to traverse the directory and get the paths as an array. But the answer defined from docu has some issues:
Therefore, a fix for the function is:
That also simplifies the code as well.
Afaik there is no option to pass wildcard *. According to: docu. We have to do it programmatically , maybe like this, where it traverses through the folders and get the path of the files, you could the just spread the
...pageStyles
into the object, where you want to insert the filepaths.