Reputation: 155
I am studying rails and using the engines with rails. In production mode, rails did not load compiled assets of engines, although I have executed:
$ RAILS_ENV=production bundle exec rake assets:clean assets:precompile
Please help if anyone knows the issue.
My settings are as below:
environment/production.rb
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_files = false
config.assets.compile = false
config.assets.digest = true
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new`
engine/xxx/lib/xxx/engine.rb
Engines's option is -- mountable
module Moderna
class Engine < ::Rails::Engine
isolate_namespace xxx
# parent company asset precompile
initializer "xxx.assets.precompile" do |app|
app.config.assets.paths << Rails.root.join("app", "assets", "fonts")
app.config.assets.precompile << %w(
xxx/*.css xxx/fancybox/*.css xxx/skin/*.css xxx/google-code-prettify/*.css
xxx/*.js xxx/flexslider/*.js xxx/google-code-prettify/*.js
xxx/portfolio/*.js xxx/quicksand/*.js
xxx/*.svg xxx/*.eot xxx/*.woff xxx/*.ttf
xxx/customicon/*.svg xxx/customicon/*.eot xxx/customicon/*.woff xxx/customicon/*.ttf
)
app.config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/
end
end
end
Upvotes: 5
Views: 3685
Reputation: 4612
EDIT Just realised this question is a bit old. The below will work for you if you add an app/assets/config/my_component_manifest.js
file to your engine and then use that to specify asset entry points.
You an also put it in the engine.rb
file:
module MyComponent
class Engine < ::Rails::Engine
config.assets.precompile += %w( my_component_manifest.js )
end
end
Upvotes: 1
Reputation: 4784
The rails engine getting started guide suggests including the following in your engine.rb
initializer "engine_name.assets.precompile" do |app|
app.config.assets.precompile += %w( admin.js admin.css )
end
It works for me.
Upvotes: 4
Reputation: 802
I faced same issue with Rails 4 engine, I resolved by adding following code to engine.rb
Rails.application.config.assets.precompile += ['*.js', '*.css', '**/*.js', '**/*.css', '*.jpg',
'*.png', '*.ico', '*.gif', '*.woff2', '*.eot',
'*.woff', '*.ttf', '*.svg']
I need to precompile all assets so wild cards are used. You can specify files.
Second option is you can specify on Host applications config/assets.rb
Rails.application.config.assets.precompile += %w( engine_name/file_name )
Upvotes: 2