【问题标题】:Best way to reference Bootstrap in a Grails 3 app在 Grails 3 应用程序中引用 Bootstrap 的最佳方式
【发布时间】:2015-08-11 01:50:50
【问题描述】:

我想将 Twitter 的 Bootstrap 引入我的 Grails 3 应用程序。最好的方法是什么?我既不想将源置于版本控制之下,也不想引用远程 CDN。

在我的 build.gradle 中添加 "org.grails:grails-bootstrap:3.0.1" 作为编译依赖项会拉下关联的 JAR,但我如何将其插入我的应用程序以最终能够从我的视图/GSP 中引用 Bootstrap 类?

【问题讨论】:

  • 你能展示你如何将 webjar 添加到你的项目中吗?
  • 您找到解决方案了吗?你能记录下结果吗?有趣的是,在 application.css 中已经有对 bootstrap 的引用。

标签: twitter-bootstrap grails grails-3.0


【解决方案1】:

Webjars 为我工作,我在 application.jsapplication.css 中使用了 webjars 链接,但这些链接并不总是很好定义(参见 typeahead 示例)

application.js:

//= require jquery-2.1.3.js
//= require_tree .
//= require_self
//= require /webjars/bootstrap/3.3.5/js/bootstrap.min
//= require /webjars/bootstrap-tagsinput/0.5/bootstrap-tagsinput
//= require /webjars/typeaheadjs/0.11.1/typeahead.bundle.js

application.css:

/*
*= require main
*= require mobile
*= require_self
*= require /webjars/bootstrap/3.3.5/css/bootstrap-theme
*= require /webjars/bootstrap/3.3.5/css/bootstrap
*= require /webjars/bootstrap-tagsinput/0.5/bootstrap-tagsinput
*/

【讨论】:

  • 你如何引用 webjars?作为依赖?我在编译期间收到错误,没有此类资产“/webjars/bootstrap/3.3.5/css/bootstrap-theme”和所有其他链接。在 grails 的缓存中,我看到了 webjar,但似乎它应该放在 grails 项目的“资产”文件夹中?
  • 您需要在 build.gradle 文件中添加依赖项(请参阅webjars 以查找您需要的依赖项)。对于引导程序 3.3.5,它是:compile 'org.webjars:bootstrap:3.3.5'
  • 是的,我在写评论之前已经这样做了。因此依赖关系出现错误。执行了其他一些操作?
  • dependencies { ... compile "org.grails:grails-web-boot" compile 'org.webjars:typeaheadjs:0.11.1' compile 'org.webjars:bootstrap:3.3.5' compile 'org.webjars:bootstrap-tagsinput:0.5' compile 'org.webjars.bower:bootstrap-table:1.8.1' ... runtime "org.grails.plugins:asset-pipeline" ... // Note: It is recommended to update to a more robust driver (Chrome, Firefox etc.) testRuntime 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.44.0' console "org.grails:grails-console" }
  • 我只添加了这个 compile 'org.webjars:bootstrap:3.3.5',也许我应该添加一些其他的 webjar 来正常工作。我查一下,谢谢。
【解决方案2】:

我认为 Grails 3 还没有任何可用的 Bootstrap 插件。我认为在你的项目中包含WebJars Bootstrap 然后在你的 gsp 或布局中引用这些文件会更容易。

我没有准备好可行的示例,但请看一下这段代码 sn-p: https://github.com/canoo/open-dolphin-lazybones-templates/commit/d1a2c3bc4d0852a331f66287314b6348d6e76e14

【讨论】:

    【解决方案3】:

    您应该使用this plugin,文档会告诉您确切的操作。

    Javascript grails-app/assets/javascripts/application.js:

    //= require bootstrap
    

    样式表 grails-app/assets/javascripts/application.css:

    /*
    *= require bootstrap
    */
    

    【讨论】:

    • 嗨,格雷格。文档引用了 BuildConfig.groovy,我相信它在 Grails 3 中已经停止使用。您能否建议如何以“新”方式引用此插件?
    • 你不会把它添加到你的 build.gradle 中吗?对不起,我真的不确定。我正在避免使用 Grails 3。:) 假设它仍在使用资产管道,我仍然相信它适用。
    【解决方案4】:

    我正在使用这个插件 kensiprell/bootstrap-framework 并将以下路径添加到 .gitignore 以便在第一次运行时下载资源。

    /grails-app/assets/javascripts/bootstrap
    /grails-app/assets/javascripts/bootstrap-all.js
    /grails-app/assets/stylesheets/font-awesome
    /grails-app/assets/stylesheets/bootstrap
    /grails-app/assets/stylesheets/font-awesome-less.less
    /grails-app/assets/stylesheets/bootstrap-less.less
    /grails-app/assets/stylesheets/bootstrap-all.css
    /grails-app/assets/stylesheets/font-awesome-all.css
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-23
      • 1970-01-01
      • 2011-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多