0

I've created 'test.js' file in 'resources/js/' and added console.log(first) to it

In the welcome.blade.php I have something like that:

<body>
  @vite(['resources/js/test.js'])
  <script type='text/javascript'>
    console.log(second)
  </script>
</body>

What I expect is to execute those scipts in order from top to bottom, however it returns output:

second
first

I guess @vite(['resources/js/test.js']) is executed asynchronously by default, but I want to change it.

Is there any better way to do this than to put all the internal JS in DOMContentLoaded?

Mako
  • 21
  • 2
  • All scripts included via vite are included as [modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) so **all** the caveats apply. It's not only execution that is defered it's also that they are only included once and are locally scoped. There's no way to change this other than use something other than vite – apokryfos Sep 16 '22 at 12:05

1 Answers1

2

Changing type from 'text/javascript' to 'module' helped.

<script type='module'>
  console.log(second)
</script>
Mako
  • 21
  • 2