首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails引擎资产没有预编译。

Rails引擎资产没有预编译。
EN

Stack Overflow用户
提问于 2016-03-14 14:56:49
回答 3查看 3.2K关注 0票数 5

我正在学习rails,并使用带有rails的引擎。在生产模式中,rails没有加载编译好的引擎资产,尽管我已经执行了:

代码语言:javascript
复制
$ RAILS_ENV=production bundle exec rake assets:clean assets:precompile

如果有人知道这个问题,请帮忙。

我的设置如下:

environment/production.rb

代码语言:javascript
复制
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

引擎的选择是.可安装的

代码语言:javascript
复制
 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
EN

回答 3

Stack Overflow用户

发布于 2017-09-14 19:28:16

rails引擎启动指南建议在engine.rb中包括以下内容

代码语言:javascript
复制
initializer "engine_name.assets.precompile" do |app|
  app.config.assets.precompile += %w( admin.js admin.css )
end

对我来说很管用。

票数 4
EN

Stack Overflow用户

发布于 2016-03-17 17:22:09

我在Rails 4引擎中遇到了同样的问题,我通过在engine.rb中添加以下代码来解决这个问题

代码语言:javascript
复制
Rails.application.config.assets.precompile += ['*.js', '*.css', '**/*.js', '**/*.css', '*.jpg',
                                '*.png', '*.ico', '*.gif', '*.woff2', '*.eot',
                                '*.woff', '*.ttf', '*.svg'] 

我需要预编译所有资产,以便使用外卡。您可以指定文件。

第二个选项是您可以在主机应用程序上指定config/assets.rb

代码语言:javascript
复制
Rails.application.config.assets.precompile += %w( engine_name/file_name )
票数 2
EN

Stack Overflow用户

发布于 2021-04-16 10:15:27

编辑刚刚意识到这个问题有点老了。如果将app/assets/config/my_component_manifest.js文件添加到引擎中,然后使用该文件指定资产入口点,下面的内容将适用于您。

您还可以将它放在engine.rb文件中:

代码语言:javascript
复制
module MyComponent
  class Engine < ::Rails::Engine
    config.assets.precompile += %w( my_component_manifest.js )
  end
end
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35990897

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档