I'm new to laravel and vite. I want to create different .js files so I can have some order. For example, I want a js for a calendar and I will use it in clockin.blade.php (and some other blade.php files). How do I call any functions in calendar.js from clockin.blade.js?
I tried with <script src="/resources/js/calendar.js">
but the console shows:
GET http://127.0.0.1:8000/resources/js/calendar.js net::ERR_ABORTED 404 (Not Found)
I tried importing it to the app.js file and then calling the funciton like this <script> asd(); </script>
but the console says asd does not exist
I also tried <script src="{{ asset('js/calendar.js') }}"></script>
(thanks for nothing, ChatGPT) but as far as I know, asset points to the public folder while calendar.js is inside /resources/js/
The <script>
tags are always inside push('scripts')
and the stack('scripts')
is inside the app.blade.php body.
My vite config is:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: [
'resources/css/app.css',
'resources/sass/app.scss',
'resources/sass/sidenav.scss',
'resources/js/app.js',
'resources/js/calendar.js',
],
refresh: true,
}),
],
});
How is this done in laravel and vite?
Edit: I also tried adding the js to @vite. Then I do this in clockin.blade.php:
<script src="/resources/js/calendar.js">
asd();
</script>
But I get the error: GET http://127.0.0.1:8000/resources/js/calendar.js net::ERR_ABORTED 404 (Not Found) If instead of a functon I just write console.log("hello world") in calendar.js, the console shows "hello world". I guess I don't know how to call functions? Also, why the downvote? (I want to improve in stack overflow)