super beginner here to both JS/Bootstrap AND webpack (familiar with HTML, (S)CSS and PHP, trying RoR now...)
I am trying to connect Bootstrap-5 to Rails-6. I have read at least 10 blog posts and many A&A here but still no luck. All Styles work, but the scripts don't. I want to create a super simple navbar - copied more or less directly from the Bootstrap template, but the drop down and the collapsed menu do not work. I linked the bootstrap scripts manually with a <script>
tag from their CDN - that did the trick but of course should not be the solution. So what stupid thing am I overlooking for making the bootstrap scripts work with Rails 6? In particular, I was looking at this post here - but still with no success :(
I have this line in my app/javascript/packs/application.js:
import 'bootstrap'
and I added these lines to my config/webpack/environment.js:
const webpack = require("webpack")
environment.plugins.append("Provide",
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
jquery: 'jquery',
'window.jQuery': 'jquery',
Popper: ['popper.js', 'default']
})
)
In app/stylesheets/application.scss (yes I renamed to scss) I have
@import "bootstrap/scss/bootstrap";
In app/views/layouts/application.html.erb, I wasn't sure what to include - I currently have three lines (added the third one):
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
The webpack compiler gives no errors. What am I doing wrong?