2

我们有一个高度模块化的 rails5 应用程序,它在多个存储库的 rails 引擎中拆分,并集成为 ruby​​ gems。

现在我们想通过使用来介绍 EmberJS ember-cli-rails。主 rails 应用程序在目录中包含主 ember 应用程序,frontend而每个 rails 引擎在目录中都包含一个 ember 引擎(通过ember-enginefrontend

如何将模块的 ember 引擎挂载到主 ember 引擎中?

4

1 回答 1

1

由于到目前为止我还没有找到其他解决方案,因此我创建了一个初始化程序,它将所有 rails 引擎的 ember 引擎目录符号链接到node_modules正在消费的 rails 应用程序中的消费 ember 引擎的目录中:

# 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

这种方法可能不是很干净,但似乎有效。

于 2016-12-16T08:51:19.520 回答