简体   繁体   中英

How to use React without NPM's “require”?

Currently I am using React on Rails application (using react-rails library) and I wish to use some third party React components.

How to use third party component without adding dependency to RequireJS, Webpack, or Browserify? To be more specific, how can I do the following command in client side JS without depending on those library?

var Select = require('react-select')

The project is currently using Rails asset pipeline heavily and I believe getting rid of it is too expensive. The assets are pulled by rails-assets

If the package/component is available through Bower you can rely on Rails Assets . Rails assets works as bridge between bower the assets pipeline allowing you to add non-gem dependencies to the pipeline.

In the specific case your mention just add the following:

Gemfile

source 'https://rails-assets.org' do
  gem 'rails-assets-react-select'
end

application.js

//= require react-select

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM