在另一个gem中包装bootstrap-sass gem会导致资产清单中断 [英] Wrapping the bootstrap-sass gem in another gem causes asset manifests to break

查看:131
本文介绍了在另一个gem中包装bootstrap-sass gem会导致资产清单中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将bootstrap-sass gem包裹在另一个gem中(我们称它为my-engine)。一路走来,我正在构建一个小型的Rails应用程序来测试事情。作为第一步,我想确保我可以直接在我的Rails应用程序中获得bootstrap-sass。 Rails应用程序的Gemfile如下所示:

  gem'bootstrap-sass','3.3.1.0'
gem'my-engine,path:〜/ dev / my-engine

这很好。引导程序资产被加载到我的Rails应用程序中,并且一切都很好。现在,我想从我的Rails应用程序中引导bootstrap-sass,并让它通过我的引擎加载。因此,我的Rails应用程序Gemfile现在看起来像:

  gem'my-engine,path:〜/ dev / my-engine 

my-engine的.gemspec包含:

  spec.add_runtime_dependency'bootstrap-sass','3.3.1.0'

我可以重新捆绑我的引擎宝石,没有任何问题。我可以重新捆绑Rails应用程序而不会出现任何问题。但是,当我刷新Rails应用程序的页面时,出现以下错误:

 要导入的文件未找到或无法读取:引导链轮。 

当链接器试图构建application.css文件时会发生这种中断。有时候这会通过,我会得到一个关于在application.js被构建时丢失bootstrap.js javascript文件的错误。



为什么会发生这种情况?我想知道这是否与我在本地开发宝石并且没有发布它们有关,尽管我不确定为什么会影响已发布的bootstrap-sass。我使用的是Bundler 1.5.3。

解决方案

请确保引擎中需要'bootstrap-sass'。一个明智的做法是在你的lib / my-engine.rb文件中:

  require'bootstrap-sass'

当您尝试在.gemspec中添加bootstrap-sass gem作为运行时依赖项时是不够的包裹宝石。

I'm trying to wrap the bootstrap-sass gem inside another gem (let's call it my-engine). Along the way, I'm building a small Rails application to test things out. As a first step, I wanted to make sure I could get bootstrap-sass working directly in my Rails application. The Gemfile for the Rails app looks like this:

gem 'bootstrap-sass', '3.3.1.0'
gem 'my-engine, path: "~/dev/my-engine"

This works fine. The bootstrap assets are loaded into my Rails application and everything looks good. Now, I want to take bootstrap-sass out of my Rails app and let it load through my-engine. So, my Rails application Gemfile now looks like:

gem 'my-engine, path: "~/dev/my-engine"

The .gemspec for my-engine has:

spec.add_runtime_dependency 'bootstrap-sass', '3.3.1.0'

I can re-bundle the my-engine gem with no problems. I can re-bundle the Rails application with no problems. However, when I refresh the page of the Rails app, I get the following error:

File to import not found or unreadable: bootstrap-sprockets.

That break occurs when sprockets is trying to build the application.css file. Sometimes this will pass and I'll get a different error about missing the bootstrap.js javascript file when the application.js is being built.

Why is this happening? I'm wondering if it has something to with the fact that I'm developing the gems locally and haven't published them, although I'm not sure why that would affect bootstrap-sass which is published. I'm using bundler 1.5.3.

解决方案

Make sure 'bootstrap-sass' is required in your engine. One sensible place to do this is in your lib/my-engine.rb file:

require 'bootstrap-sass'

Adding the bootstrap-sass gem as a runtime dependency in the .gemspec isn't enough when you're trying to wrap gems.

这篇关于在另一个gem中包装bootstrap-sass gem会导致资产清单中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆