Win*_*zan 8 ruby rubygems ruby-on-rails node.js npm
我正在构建打包在gem内的Ruby on Rails引擎,无法弄清楚如何确保加载了NPM依赖项。
在常规的Rails应用程序中,您可以安装NPM,然后使用npm install
命令将软件包放入node_modules
基本目录中。然后node_modules
将以下行添加到资产管道中application.rb
:
config.assets.paths << Rails.root.join('node_modules')
Run Code Online (Sandbox Code Playgroud)
但是,就我而言,我正在构建一个Rails引擎,将其作为gem加载。该.gemspec
文件可让您的gem将其他Ruby依赖项加载到主机应用程序中,但是我不知道如何对Node依赖项执行相同的操作。在我的引擎中注意到需要某些NPM模块才能将其安装在主机应用程序中的正确方法是什么?
你见过npm-pipeline-rails吗?
从文档:
npm-pipeline-rails 允许您在 Rails 应用程序生命周期中挂钩某些命令,通常是 npm 脚本。它假定您的工具将把普通的 JS 和 CSS 文件构建到供应商/资产中,允许它被 Rails 的资产管道接收。
它不会取代 Rails 资产管道,而是与之配合使用。您使用 npm 管道构建的文件将作为 Rails 资产管道中的常规文件提供。
还有一个示例应用程序配置:
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 = true
end
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
525 次 |
最近记录: |