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.
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)?
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.
Thanks!
Example: Let the local-dir is the local directory and project-dir is the project directory and local_module is the local module package you want to install, first go to the local-dir and type npm link and next go to the project directory and type npm link <local_module> this will link your local module to your project.
NPM is a package manager for Node based environments. NPM manages dependencies and store its data in file package. json .
As previously stated, Yarn installs dependency packages in parallel, whereas NPM installs them sequentially. As a result, Yarn outperforms NPM when installing bigger files. Both tools can save dependent files to the offline cache.
A package. json is a JSON file that exists at the root of a Javascript/Node project. It holds metadata relevant to the project and it is used for managing the project's dependencies, scripts, version and a whole lot more.
To include npm packages in a rails project using the asset pipeline, do the following:
Initialise your package.json: npm init
Add node_modules
to your asset path:
# config/application.rb
module YourApp
class Application < Rails::Application
config.assets.paths << Rails.root.join('node_modules')
end
end
npm install
runs on startup by adding an initializer:# config/initializers/npm.rb
system 'npm install' if Rails.env.development? || Rails.env.test?
Install your package: npm install YourPackage
Link to your package from app/assets/javascripts/application.js
:
//= require /Path/To/YourPackage
Rails 5.1 supports including npm packages using Yarn.
For example, let’s say we want to use the moment.js library. We need first of all install the library using Yarn:
yarn add moment
We can see that package.json was updated:
{
"name": "yarn_test",
"private": true,
"dependencies": {
"moment": "^2.18.1"
}
}
And finally we need to include the new package to application.js:
//= require moment/moment
See Rails 5.1 and forward - Part 1: Yarn on Rails
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With