I use Laravel with Vite and I want to add file with Vanillia JS code. Before I used mix and I have never use Vite before. I tryed add this code into file vite.config.js like below example:
laravel({
input: [
'resources/sass/app.scss',
'resources/js/app.js',
'resources/js/test.js', //this is my code
],
refresh: true,
}),
but it doesn't work. I need to add one library and code with config that. Could you help me?
This is applicable for your own created js files and node modules library js files
You need to both declare it in vite.config.js and initial HTML file (app.blade.php / welcome.blade.php)
In vite.config.js
export default defineConfig({
plugins: [
laravel({
input: [
'resources/css/app.css',
'resources/js/app.js',
'resources/js/test.js', //your custom js
'node_modules/flowbite/dist/flowbite.js', //node modules js
'node_modules/flowbite/dist/datepicker.js'
],
refresh: true,
}),
],
});
In HTML.blade.php
<head>
@vite(['resources/css/app.css', 'resources/js/app.js',
'resources/js/test.js',node_modules/flowbite/dist/flowbite.js'
,'node_modules/flowbite/dist/datepicker.js'])
</head>
P.S: I am using Flowbite plugin as an example here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With