我如何使用 bootstrap 与 rails 做出反应

How can I use bootstrap in react with rails

我试过使用 npm 包 reactstrap。 我的组件:

import { Col, Button, Form, FormGroup, Label, Input, FormText } from 'reactstrap';

我收到以下错误:

ExecJS::ProgramError at /dir/xyz
TypeError: require is not a function

webpacker-gem 是 react + rails 的方式,而不是 sprockets,这对于 jQuery 风格的 JS 是可以的,但不适用于复杂的基于 ES6 的堆栈。

来自自述文件:

To use Webpacker with React, create a new Rails 5.1+ app using --webpack=react option:

# Rails 5.1+
rails new myapp --webpack=react

(or run bundle exec rails webpacker:install:react in a existing Rails app already setup with Webpacker).

The installer will add all relevant dependencies using Yarn, changes to the configuration files, and an example React component to your project in app/javascript/packs so that you can experiment with React right away.

请注意,从那时起您将使用 yarn,而不是 npm。