Wrapping the bootstrap-sass gem in another gem causes asset manifests to break

后端 未结 2 1326
梦如初夏
梦如初夏 2021-01-14 09:27

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 fi

相关标签:
2条回答
  • 2021-01-14 09:39

    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.

    0 讨论(0)
  • 2021-01-14 09:55

    As you want to use more and more scss/js/coffeescript libraries, you may want to consider moving to bower vs gemfiles as the source for bootstrap-sass-official. We use bower-rails for rake tasks and auto-configuration. It's a really lite config/rake task layer over standard bower.

    Addressing your answer, bootstrap problems via the gem was one of the reasons I switched our engine over to just bower assets. We now import bootstrap-sass-official and have full control, note however that for sass files you will need to import the longer path to the source file, i.e. in our engine _application.scss:

    # our custom variable overrides
    @import 'overrides/variables';
    
    @import 'bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets';
    @import 'bootstrap-sass-official/assets/stylesheets/bootstrap';
    

    NOTE: if you want your app sass variables to override engine and sass variables, make sure your engine has _application.scss not application.scss, the leading underscore is critical for variable context/scope.

    Thinking ahead, you may need to ignore bower transitive dependencies as we did. (i.e. some dependencies may use 'bootstrap' while others use 'bootstrap-sass-official' etc)

    We use it like this in our .bowerrc such as the following:

    {
      "ignoredDependencies": [
        "bootstrap",
        "bootstrap-sass",
        "bootstrap-sass-official"
      ]
    }
    

    In conclusion We have been using this for several months with success. bower-rails will install the dependencies in /vendor/assets and if referenced in your engine, you won't need to reference them at all in your application project. It has been fast and easy to maintain/add/update libraries and know exactly how files are included.

    0 讨论(0)
提交回复
热议问题