Installing https://github.com/twbs/bootstrap-rubygem on rails 6 alpha

孤街浪徒 提交于 2020-01-04 03:17:31

问题


How do you install the bootstrap gem (https://github.com/twbs/bootstrap-rubygem) on rails 6?

The bootstrap README asks us to add things to application.js but rails 6 doesn't seem to have an application.js in the usual place.

[ Rails 6.0.0.alpha ] bundle exec rails new noname --edge --database=postgresql --webpacker=react


回答1:


If you use webpacker, you may want to use the npm package of bootstrap

yarn add bootstrap@4.0.0 popper.js

and

# app/javascript/packs/application.js
import 'bootstrap/dist/js/bootstrap';

and inside stylesheets.scss

@import '~bootstrap/scss/bootstrap';

Please look at the complete steps here: https://medium.com/@coorasse/goodbye-sprockets-welcome-webpacker-3-0-ff877fb8fa79




回答2:


This is the most basic solution for me:

Install bootstrap, jquery and popper.js with yarn:

$ yarn add bootstrap
$ yarn add jquery
$ yarn add popper.js

Then require bootstrap JS and CSS in app/javascript/packs/application.js:

require('bootstrap')
require('bootstrap/dist/css/bootstrap.min.css')

Note: If you need to use SCSS to customize Bootstrap then this solution is not proper for you. Use @coorasse's solution above.



来源:https://stackoverflow.com/questions/54206656/installing-https-github-com-twbs-bootstrap-rubygem-on-rails-6-alpha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!