6

I want to include a custom JavaScript in the app.js file which as the following code:

window.$ = window.jQuery = require('jquery')
require('bootstrap-sass');

The require only works for published packages and using node install but I want to know if there is a way to include a custom js in this file in order to have just one built script in my app (in this case the app.js script).

3 Answers 3

7

Add your scripts under this path \resources\assets\js\,

(ex : \resources\assets\js\scripts\my_script.js & \resources\assets\js\another_script.js)

And, add them to \resources\assets\js\app.js

require ('./scripts/my_script.js');
require ('./another_script.js');
Sign up to request clarification or add additional context in comments.

Comments

0

Just add your script in resources/assets/js and then run gulp to compile all your scripts into app.js Check this for more info

Comments

0

I presume you have other files that are not exactly VueJs files and you want to build into a single script. In that case it is not good to put the script in that file. You can however place the files in your resources/assets/js folder and add some code to your gulpfile.js to build all your scripts into one file. Here is the code you might need to add.

 mix.scripts([
   'filename.js',
 ]);

By default, the build file will be placed in public/js/all.js.

You can customise that driectory by modifying the example above to something like this

mix.scripts([
  'filename.js
], 'path/to/file.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.