我是rails的新手,正在使用React作为前端。理想情况下,我希望能够进入我的组件,并在顶部放置一个导入语句,如下所示:
从'npm-package‘导入npmpackage
似乎我无法做到这一点,并且当我尝试运行服务器时,总是从rails得到某种类型的错误。我听说过我使用的rails版本(5.1.3)允许使用像这样的es6、es6和import语句。
有没有人能给我解释一下,或者把我链接到一个很好的指南,告诉我如何做到这一点?Google似乎将我链接到无用的指南或使用Rails4或更早版本的过时指南。
这是我的application.rb文件:
require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Mediumrails
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.assets.paths << Rails.root.join('node_modules');
config.load_defaults 5.1
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
end
end
发布于 2017-08-25 00:03:32
如何(在Rails 5.1+中):
rails new my-react-rails-app webpack=react或者将gem 'webpacker'添加到Gemfile并捆绑它。然后运行./bin/rails webpacker:install:react,给rails留出一些时间来准备一切:)
也许this post能帮上忙。
干杯!
https://stackoverflow.com/questions/45853060
复制相似问题