简体   繁体   中英

Laravel mix, call app.js in resources

I have a web app with laravel and vuejs. I use laravel-mix and in my webpack.mix.js I have:

mix.js('resources/assets/js/app.js', 'public/js')

In the view I have

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

But it still does not run, I think it could be interfered by <base href="{{asset('')}}"> card.

I run npm run watch but still no error message. In my website app.js can run but the other libraries get lost.

I always do these steps and it works please try these:

1)install laravel mix npm i

2)in webpack :

 mix.js('resources/assets/js/app.js', 'public/js');
mix.js('resources/assets/js/admin.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css')
.sass('resources/assets/sass/admin.scss', 'public/css');

please include your css and javascript files in new files like here in admin.js and admin.scss

3)in admin.scss include your css files for example :

@import "files/sweetalert.css";

4)in admin.js include your js files for example :

mix.combine([
    'files/jquery.js',
]);

5)in blade include js and css files:

<script src='js/admin.js'"></script> 
<link rel="stylesheet" href="css/admin.css">

6)run npm run watch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM