【发布时间】:2017-06-05 19:18:09
【问题描述】:
在 Grails 3.2.9 中使用 Bootstrap 的方法是什么?如何开始?我应该使用任何插件吗?
【问题讨论】:
标签: twitter-bootstrap grails plugins installation
在 Grails 3.2.9 中使用 Bootstrap 的方法是什么?如何开始?我应该使用任何插件吗?
【问题讨论】:
标签: twitter-bootstrap grails plugins installation
要遵循最佳做法,请使用Grails Asset Pipeline。了解管道的工作原理可能需要一些练习,但在此SO Answer 中很好地突出了一般思想。管道将为您的资产创建文件夹(例如 css、javascript、图像),您需要将引导文件放置在适当的位置。确保你记得Bootstrap requires jQuery.
请注意所有 JavaScript 插件都需要 jQuery...
所以一定要在你的 javascript 文件夹中包含 jQuery。要掌握的另一个概念是创建清单文件。对于 javascript 资产,它可能类似于:
示例文件路径:
grails-app/assets/javascripts/application.js
示例文件内容:
//This is a JavaScript file with its top level require directives
//= require jquery
//= require app/models.js
//= require_tree views
//= require_self
console.log("This is my javascript manifest");
然后在您想要使用资产的视图中,通过声明包含引导资产:
<head>
<asset:stylesheet href="application.css"/> //This assumes the standard pipeline path
<asset:javascript src="application.js"/>
<asset:link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
</head>
希望这可以帮助您开始通过资产管道加载 Bootstrap。
【讨论】:
您可以使用webjars
build.grade
dependencies {
...
compile "org.webjars:bootstrap:3.3.5"
}
grails-app\stylesheets\application.css
*= require /webjars/bootstrap/3.3.5/css/bootstrap
grails-app\javascripts\application.js
//= require /webjars/bootstrap/3.3.5/js/bootstrap.min
【讨论】: