I have hard time understanding the difference between "require" and "import" inside application.js file (Rails 6).
I've got an excerpt of Michael Hartl's book that describes the way to add jquery & bootstrap to my app.
Steps:
yarn add jquery@3.4.1 bootstrap@3.4.1
then add to config/webpack/environment.js
const { environment } = require('@rails/webpacker')
const webpack = require('webpack')
environment.plugins.prepend('Provide',
new webpack.ProvidePlugin({
$: 'jquery/src/jquery',
jQuery: 'jquery/src/jquery'
})
)
module.exports = environment
and finally in application.js:
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require("jquery")
import "bootstrap"
The question is - why is jquery required, and bootstrap imported? Thank you,
Update
EDIT - the comment by @arieljuod has helped me to look for solution in javascript realm, I'll leave the question just for future reference. application.js is a javascript file and has nothing to do with rails itself.