0

I my project I am using Bootstrap.js, Jquery.js , Jquery_validation.js and one custom.js(for project specific rules).

I want to use only one app.js on all pages. what is the best way to use webpack.mix ?

I have installed jquery and jquery-validation , Please suggest me.

package.json

"devDependencies": {
    "axios": "^0.19",
    "bootstrap": "^4.0.0",
    "cross-env": "^7.0",
    "jquery": "^3.2",
    "laravel-mix": "^5.0.1",
    "lodash": "^4.17.13",
    "popper.js": "^1.12",
    "resolve-url-loader": "^2.3.1",
    "sass": "^1.20.1",
    "sass-loader": "^8.0.0",
    "vue": "^2.5.17",
    "vue-template-compiler": "^2.6.10"
},
"dependencies": {
    "jquery-validation": "^1.19.1",
    "savvy-js": "^1.0.7"
}

in resource/js/app.js

require('jquery-validation');

require('./bootstrap');

window.Vue = require('vue');

webpack.mix

mix.js(['resources/js/app.js','resources/js/snavvy.js'], 'public/js')

.sass('resources/sass/app.scss', 'public/css') .options({ processCssUrls: false });

So Please tell me how to use bootstrap.js, jquery.js, jquery-validation.js and custom.js(resource/js/custom.js) in best way ?

3
  • This is a pretty standard laravel setup. In your app.blade.php, you should have <script src="{{ asset('js/app.js') }}"></script> which includes the script you've created. Commented May 17, 2020 at 5:47
  • Yes, I am using it but I have multiple js (bootstrap,jquery,jquery_validation & one custom js) so need to combine them. Commented May 17, 2020 at 6:01
  • Have you run "npm run production" yet? Commented May 17, 2020 at 6:21

2 Answers 2

2

The webpack.mix.js need the file extensions; the folder is not enough. I usually link the .sass to my view. Something like


//does not work
mix.js(['resources/js/app.js','resources/js/snavvy.js'], 'public/js');


//sucessful
mix.js('resources/js/app.js','public/js');

//or if you want a custom name
mix.js('resources/js/snavvy.js', 'public/js/custom_snavvy.js');
npm run dev

//or

npm run watch

Good luck.

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

6 Comments

I added file name with extention. mix.js(['resources/js/app.js','resources/js/snavvy.js'], 'public/js/app.js'), but still snavvy is not working.
try take out '[' and ']' and put the .js views at separated mix.js class.
i'ts exactly as "//sucessful" it
new editied answer creating two js files in public/js folder then what is advantage of webpack.mix .
compile the files to a certain directory with their appropriate libraries. This is just an syntax issue
|
0

This solution worked for me:

mix.js([
    'resources/js/app.js',
    'resources/js/jquery-2.2.4.min.js',
    'resources/plugins/bootstrap-3.3.6/js/bootstrap.min.js',
     ...
], 'public/js/app.js').version();

Further Details

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.