如何在Rails中使用npm软件包 [英] how to use npm packages in rails
问题描述
我正尝试在Ruby on Rails应用程序中使用 Ace编辑器,其中大多数视图组成为React组件。我正在使用反应轨道gem ,并且根本没有使用助焊剂。
I'm trying to use the Ace editor in my Ruby on Rails app, with majority of the view composed as React components. I'm using the react-rails gem and I'm not using flux at all.
我发现了这个 react-ace 软件包,但我必须使用npm进行安装。我已经能够将Bower组件与Bower-rails gem配合使用,但从未使用过npm软件包。有没有办法仅通过资产管道(通过供应商)使用此方法?
I found this react-ace package, but I have to use npm to install it. I've been able to get bower components working with bower-rails gem but never got npm packages to work. Is there a way to use this just through the asset pipeline (through vendor)?
顺便说一句,我没有使用browserify或ES6,所以我什至没有 import
。到目前为止,我一直在通过资产管道进行所有操作。
By the way, I'm not using browserify or ES6 so I don't even have import
. I've been doing everything through the asset pipeline so far.
谢谢!
推荐答案
要使用资产管道将npm软件包包含在Rails项目中,请执行以下操作:
To include npm packages in a rails project using the asset pipeline, do the following:
-
初始化您的软件包.json:
Initialise your package.json:
npm初始化
将 node_modules
添加到您的资产路径:
Add node_modules
to your asset path:
module YourApp
类Application < Rails :: Application
config.assets.paths<< Rails.root.join('node_modules')
确保 npm安装
在启动时运行:
在 config / initializers / npm.rb
:
系统'npm install'如果Rails.env.development? || Rails.env.test?
安装软件包:
npm安装YourPackage
从application.js链接到您的软件包
Link to your package from application.js
// =要求/ Path / To / YourPackage
这篇关于如何在Rails中使用npm软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!