After installing npm packages in Laravel, how do I require them?
For example, let's say I need the package sweetalert2
. To install it, run the command:
npm install --save sweetalert2
Now, do I need to include it in the
\resources\assets\js\bootstrap.js
file in Laravel?
The default content of the file is as follows:
window._ = require('lodash');
try {
window.$ = window.jQuery = require('jquery');
require('bootstrap');
} catch (e) {}
window.axios = require('axios');
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = window.Laravel.csrfToken;
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
It seems like lodash
,jquery
,bootstrap
, and axios
have been included in Laravel, but the way they are required varies in each sentence, which can be seen below:
window._ = require('lodash');
window.$ = window.jQuery = require('jquery');
require('bootstrap');
window.axios = require('axios');
Questions:
1. Why do the four sentences differ in their requirements for these packages?
2. If I want to include the package sweetalert2
, how should I write it?