Ember发动机通过ember-cli-rails引擎通过ember-cli-rails
问题描述:
我们有一个高模块化的rails5应用程序,它在轨道引擎中分成多个存储库并集成为红宝石宝石。Ember发动机通过ember-cli-rails引擎通过ember-cli-rails
现在我们想通过使用ember-cli-rails
来介绍EmberJS。主导轨应用程序包含frontend
目录中的主要应用程序应用程序,而每个导轨引擎在frontend
目录中包含一个支持引擎(通过ember-engine
)。
如何将模块的余烬引擎安装到主要的余烬引擎中?
答
由于事实上,我发现到目前为止,我已经创建了所有的符号连接钢轨发动机的余烬引擎目录到消费烬发动机的node_modules
在消费Rails应用程序的初始化没有其他解决办法:
# Get the node_modules dir
nm_dir = Rails.root.join('frontend', 'node_modules')
# Delete existing symlinks
Dir.new(nm_dir.to_s).each { |entry| FileUtils.rm_rf(entry) if entry =~ /^.+\-frontend$/ }
# MODULES contains an array of the rails engine gem names
MODULES.each do |module_name|
# Each module has a Manifest class, load that
manifest = load_manifest(module_name)
# Get the path to the frontend dir of the rails engine
source = Pathname.new(manifest.method(:setup).source_location[0].split('/lib/')[0]).join('frontend').to_s
# Symlink destination
destination = nm_dir.join("#{module_name}-frontend").to_s
# Symlink it
FileUtils.symlink source, destination, force: true
end
这种方法可能不是很干净,但它似乎工作。
同时我发现了'npm link'并重建了上面的代码片段来使用npm链接,而不是手动创建符号链接。 https://docs.npmjs.com/cli/link – phortx