Node / NPM dependency with Ruby on Rails engine gem asset pipeline Node / NPM dependency with Ruby on Rails engine gem asset pipeline node.js node.js

Node / NPM dependency with Ruby on Rails engine gem asset pipeline


Have you seen npm-pipeline-rails?

From the documentation:

npm-pipeline-rails allows you to hook certain commands, usually npm scripts, during the Rails app lifecycle. It assumes that your tool will build plain JS and CSS files into vendor/assets, allowing it to be picked up by Rails's asset pipeline.

It does not replace the Rails asset pipeline, but rather it works with it. The files you build with your npm pipeline will be available as regular files in the Rails asset pipeline.

There is also a sample application configuration:

Rails.application.configure do  # Enables npm_pipeline_rails's invocation of `watch` commands. (v1.5.0+)  # If `true`, watch commands will be ran alongside Rails's server.  # Defaults to true in development.  config.npm.enable_watch = Rails.env.development?  # Command to install dependencies  config.npm.install = ['npm install']  # Command to build production assets  config.npm.build = ['npm run build']  # Command to start a file watcher  config.npm.watch = ['npm run start']  # The commands are arrays; you may add more commands as needed:  config.npm.watch = [    'npm run webpack:start',    'npm run brunch:start'  ]  # If 'true', runs 'npm install' on 'rake assets:precompile'. (v1.6.0+)  # If you disable this, you'll need to run `npm install` yourself.  # This is generally desired, but you may set this to false when  # deploying to Heroku to speed things up.  config.npm.install_on_asset_precompile = true  # If 'true', runs 'npm install' on 'rails server'. (v1.7.0+)  # If you disable this, you'll need to run `npm install` yourself.  config.npm.install_on_rails_server = trueend