Ember CLI app inside a Rails engine

385 Views Asked by At

I'm making a Rails engine that has an /admin route. I'd like to create this admin interface with Ember CLI.

I know rails will automatically precompile any static JS/CSS that live in my engine's lib dir, and only load them when the parent application mounts my engine and visits that route. However, I'd like to use Ember CLI to build the admin interface.

What would be a good way to do this? Ideally I'd like to keep Ember CLI builds out of the repo.

1

There are 1 best solutions below

0
On BEST ANSWER

My solution involved storing a build of the Ember CLI app in the engine.

I wrote a rake task that runs ember build and moves the static dist into the public/my-engine directory, and merges those public static assets with the host app's public folder.

Here's the task for our particular project:

namespace :admin do
  task :build do
    Dir.chdir('admin') do
      sh 'ember build  --environment=production'
    end

    # Copy the dist to public
    FileUtils.rm_r 'public/front_end_builds'
    FileUtils.mv 'admin/dist', 'public/front_end_builds'

    # Move the index out of public
    FileUtils.mv 'public/front_end_builds/index.html', 'app/views/front_end_builds/admin/index.html.erb'
  end
end