Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember CLI app inside a Rails engine

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.

like image 351
Sam Selikoff Avatar asked Nov 14 '14 20:11

Sam Selikoff


1 Answers

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
like image 68
Sam Selikoff Avatar answered Oct 17 '22 23:10

Sam Selikoff