0

I installed a fresh Laravel 5.8 and included the

<script src="{{asset('js/app.js')}}"></script>

at the bottom of welcome.blade.php. To avoid error, set a div with id=app.

If I write alert(123) inside public/js/app.js it will be alerted when I visit this page and it is ok. I noticed that in line 60329 of public/js/app.js it has

webpack_require(/*! C:\xampp\htdocs\br1\resources\js\app.js */"./resources/js/app.js");

sounds it includes the resources\js\app.js and resources\js\app.js includes resources\js\bootstrap.js

When I write the alert(22) in resources\js\app.js or resources\js\bootstrap.js nothing will be alerted while it must alert something.

Thanks in advance.

2 Answers 2

3

The public/js/app.js file is a file built from the resources in resources/js/app.js. If you want to modify the javascript, you should update the resources/js/app.js and compile these resources using npm run dev in your terminal.

More information about compiling resources can be found in the documentation: https://laravel.com/docs/7.x/mix

Sign up to request clarification or add additional context in comments.

Comments

1

Your laravel application is loading javascript from public/app.js. That is why when you add the alert directly in public/app.js the alert shows up just as you would expect. To update this file after making changes to resources/js/app.js you would have to run the npm run dev command from the terminal. This will compile the code in resources/js/app.js and consequently update public/app.js

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.