如何在Rails中使用npm软件包 [英] how to use npm packages in rails

查看:104
本文介绍了如何在Rails中使用npm软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在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:


  1. 初始化您的软件包.json:

  1. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆