[英]install bootstrap gem or yarn add bootstrap for rails 5.1 or both
After getting a project setup in rails 5.1 with --webpack=react option should I install the bootstrap gem? 在rails 5.1中使用--webpack = react选项进行项目设置后,我应该安装bootstrap gem吗? or use yarn add bootstrap?
或使用纱线添加引导程序? Or would I need both if I'm using rails and react components throughout a project?
或者如果我在整个项目中使用rails并对组件做出反应,我是否需要两者?
Also, are there pros and cons of either method? 另外,这两种方法都有利弊吗?
It depends on where you want to use Bootstrap. 这取决于您要使用Bootstrap的位置。
In the case you need it, in a app/views/*/*.html.erb
for instance, you would need the gem, and require it in the Rails assets pipeline in the app/assets/stylesheets/application.scss
and same for JavaScript file. 如果您需要它,例如在
app/views/*/*.html.erb
中,您将需要gem,并在app/assets/stylesheets/application.scss
中的Rails资产管道中需要它,并且相同用于JavaScript文件。
But as you mentioned you created your Rails application with --webpack=react
, I guess you'd like to use Bootstrap in your client side application, so the app/javascript
folder and not the Rails assets ( app/assets
). 但正如你所提到的,你用
--webpack=react
创建了你的Rails应用程序,我想你想在你的客户端应用程序中使用Bootstrap,所以app/javascript
文件夹而不是Rails资产( app/assets
)。 In this case you will have to install it using yarn
. 在这种情况下,您将不得不使用
yarn
安装它。
You have to see the app/assets
as the "old way", or the non-javascript framework way (which isn't fully true as you have some gems to install React or AngularJs etc...), and you should see app/javascript
the new way, with webpacker, so using a JavaScript framework and being an app 100% JavaScript (while in the assets you'll use some .erb
files). 您必须将
app/assets
视为“旧方式”,或非javascript框架方式(由于您有一些宝石可以安装React或AngularJs等等,这不完全正确),您应该看到app/javascript
新的方式,使用webpacker,所以使用JavaScript框架并成为应用程序100%JavaScript(在资产中你将使用一些.erb
文件)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.